You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just started to use this package but as a beginner to laravel i'm not really sure if it's the way or not. I have Documents, and each document can have roles assigned to. Then we retrieve the documents only if the signed in user has the given role that is assigned to the Document(s).
Below i give an example i tried. I seems to work but feels a bit off, i'm not sure...
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I just started to use this package but as a beginner to laravel i'm not really sure if it's the way or not. I have Documents, and each document can have roles assigned to. Then we retrieve the documents only if the signed in user has the given role that is assigned to the Document(s).
Below i give an example i tried. I seems to work but feels a bit off, i'm not sure...
Any advise would be great
QueryBuilder::for(Document::class) ->allowedFilters([ 'subject', AllowedFilter::custom('category', new FiltersDocumentCategory) ]) ->with('category') ->whereHas('roles', function (Builder $query) { $query->where('id', '=', Auth::user()->hasAllRoles(Role::all())); }) ->orderBy('updated_at', 'desc') ->orderBy('number', 'desc') ->paginate($request->get('perPage', 10));
Beta Was this translation helpful? Give feedback.
All reactions