my tables :
users :
id fname email
brands:
id title user_id_made
each brand has a user_id_made
that is a foreign key
of users
table.
in Brand
model :
public function user()
{
return $this->hasOne('App\Models\User','id');
}
in User model:
public function brand()
{
return $this->belongsTo('App\Models\Brand','user_id_made');
}
I have a list of brands like this :
title of brand - email of user that made it
in my controller I write this code :
$data['brands'] = Brand::with('user')->simplePaginate(2);
in foreach
of view I got trying to get non-object property
error :
@foreach($brands as $brand)
<tr>
<td></td>
<td></td>
<td></td> // error line
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2dr4FLm
via IFTTT
Aucun commentaire:
Enregistrer un commentaire