Może przejdę do porblemu.
baza:
-products
-categories
model
-category
<?php protected $fillable = [ 'name', 'img' ]; public function products(){ return $this->belongsToMany('App\Product'); } ?>
-product
protected $fillable = [ 'category_id', 'product_number', 'img' ]; public function categories(){ return $this->belongsToMany('App\Category'); }
controller category
@foreach($category as $article) {{ $article->name }} // DZIAŁA <ul> @foreach($article->products as $tag) // ZWRACA BŁĄD <li>{{ $tag->id }}</li> @endforeach </ul> @endforeach
błąd:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'lavarel.category_product' doesn't exist (SQL: select `products`.*, `category_product`.`category_id` as `pivot_category_id`, `category_product`.`product_id` as `pivot_product_id` from `products` inner join `category_product` on `products`.`id` = `category_product`.`product_id` where `category_product`.`category_id` = 1)
Mógłby ktoś nakierować mnie na rozwiązanie tego problemu?