0
users :
id fname email
brands:
id title user_id_made
每个用户都有许多brand
S和每个brand
belongsTo关系的user
。
class Brand extends Model
{
protected $table = 'brands';
protected $fillable = array('title_fa',
'title_en','logo','user_id_made');
public function user()
{
return $this->hasOne('App\Models\User');
}
}
class User extends Authenticatable
{
use Notifiable;
protected $fillable = [
'fname' ,'lname' , 'username', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
public function brand()
{
return $this->belongsTo('App\Models\Brand','user_id_made');
}
}
我的代码没有任何关于用户的输出。
$data['brands'] = \DB::table('brands')->find(1);
var_dump($data['brands']);
return;
我有一个列表作为品牌,它内部我想显示制作该品牌的用户的电子邮件。 –
你想要显示品牌与用户的电子邮件ID谁创建? – Vikash
是的。现在如何获取用户信息?! '$ brand-> User-> fname'不起作用。 –