Open t0n1zz opened 6 years ago
I think u have to use WhereHas method
whereHas? care to explain more? i'm still not really understand about whole eloquent and collection thing works in laravel...
and for more information roles
table is from spatie permission package and i just happen to find out i can get those related roles to the user model by using with
like that
In order to filter the results by relationship you have to use whereHas
method.
For example:
User::with(['a', 'b', 'etc'])
->whereHas('roles', function($query) {
$query->where('name', '=', 'admin'); // any search function
})->get();
The above code is not tested.
hmm but i'm in situation where i don't know which roles name will be, in fact i trying to get those roles name. so i am calling user model and roles that have relation with those user model.... i trying to make a list of table with user model (name, username, etc) with roles that those user model have.
hi, i love your project and it works very well and match what i need for an spa project with laravel. But i don't quite get it how everything works... and now i having a hard time to using it with json data that returned like this
so according to the json data returned above i want to user
roles
forsearch_column
, i tried to useroles.name
but it is not working so any idea to use those?my controller is like this