i created 3 tables : users , roles and role_user.
the user model :
public function roles()
{
return $this->belongsToMany('Role');
}
it is ok, i can get the relation
$roles = User::find(1)->roles;
But when i changed
$roles = User::where('name', 'Test')->get()->roles;
Undefined property: IlluminateDatabaseEloquentCollection::$roles
So that is some wrong or 'find', 'where' is difference ? if i want use where for fetch relation , how can i do ?
See Question&Answers more detail:os