dimanche 17 octobre 2021

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged user role, I need to limit the results only to 3 for security reasons and at the moment this is not working:

public static function indexQuery(NovaRequest $request, $query)
{
    if(auth()->user()->role != 'admin') return $query->limit(3);

    return $query;
}

The result:

enter image description here

Looks like the condition is not taken into consideration.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire