I know its basic but cant figure it out whats the problem. its seems like i did all things right. I want to make a relation ship with product brands where every product has a brand id which belongs to a Brands also in brands model every brands has many products. i used belongsTo has many relationship to make this but still its showed me error.
Product.php
model
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $fillable = [
'sku',
'name',
'description',
'brand_id',
'image',
'price',
'stocks',
'color',
'size',
];
protected $table = 'products';
public function brand() {
return $this->belongsTo('App\Brand');
}
}
Brand.php
model
namespace App;
use Illuminate\Database\Eloquent\Model;
class Brand extends Model
{
protected $fillable = [
'user_id',
'name',
'description'
];
protected $table = 'brands';
public function products() {
return $this->hasMany('App\Product','brand_id', 'id');
}
}
routs.php
Route::get('/', function () {
$products = \App\Product::all();
echo $products->brand();
});