HOW To Use where clause in egar loading eloquent Query in Laravel
I'm working on ACL system. during working on system I've face a challenge.
Here is my query , How can i use where clause in this query...
$this->roles()->with('permissions')->get()->pluck('permissions')
@JAHELLER -
Auth::user()->roles()->with(['permissions'=>function($q){$q->where('permissions.id','=',3);}])->get()->pluck('permissions');
I'm try this way but it's return empty an array.
You don't have to use permissions.id, just use id. Try to debug the query piece by piece, to see where things go wrong.
->pluck() is working on roles not on the permissions table
If you just want permissions then just use;
Auth::user()
->roles()
->with('permissions'=>function($q) {
$q->where('id',3);
})
->get()
->permissions;
It might be easier to tell us what you are trying to do.
@SNAPEY - it's refers an error
** Property [permissions] does not exist on this collection **
Auth::user()->roles()->with(['permissions'=>function($q){$q->where('permission_id','=',3);}])->get()->permissions
sorry, yes, this is a collection (an array) of roles, each will have permissions
Please or to participate in this conversation.