Looks like you could use query scopes more efficiently. I usually have a helper class that in the background figures out and returns who can do what.
See
https://laracasts.com/discuss/channels/laravel/using-laravel-policy-to-filter-eloquent-query
and
But scopes would reduce clutter, and a class in the background could just return to the scope if someone can or cannot do something.
I have switched to scopes now since snapey suggested.
public function scopegetPets($query, $petsearch = '')
{
$petsearch = $petsearch . "%";
$query = Pet::where('petname', 'like', $petsearch);
if (ChkAuth::userRole('admin') === false) {
$userid = Auth::user()->id;
$query->where('ownerid', '=', $userid);
}
$results = $query->orderBy('petname', 'asc')->paginate(5);
return $results;
}
If admin show all, otherwise just show the users data.
Not saying do it exactly like this, but you could have a class to call that works in the background to resolve this stuff. I just made a helper class, but you can decide for yourself the easier way.
A couple more:
https://laracasts.com/discuss/channels/laravel/permissions-and-roles
https://stackoverflow.com/questions/43901719/laravel-middleware-with-multiple-roles