0👍
*** Here Category HasMany Products where Foreign Key Is productcategory_id.
class Category extends Model
{
public function products(){
return $this->hasMany(Product::class,’productcategory_id’);
}
}
***** Every Product belongsTo A Category..**
class Product extends Model
{
public function category(){
return $this->belongsTo(Category::class);
}
}
Think Like this.
Source:stackexchange.com