modele:
class Product extends Model { protected $fillable = [ 'category_id', 'product_number', 'img' ]; public $table = 'products'; public function categories(){ return $this->belongsToMany('App\Category'); } public function getCategoryIdAttribute(){ dd($this->categories->lists('id')->ToArray()); <-- tu jest błąd } }
class Category extends Model { protected $fillable = [ 'name', 'img' ]; public $table = 'categories'; public function products(){ return $this->hasMany('App\Product'); } }
mysql:
-categories
:id
:name
-products
:id
:category_id
error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'lavarel.category_product' doesn't
Rozumiem że błąd mam z pivotami?