Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

birdietorerik's avatar

How to add filter here ?

Hi!

Have a vueform to create new users. But administrator that registrer new users, cant use all roles.

So i want this function, to return all roles exept the role with id=4

Tryed this, but dosent work ?

 public function create(User $user)
    {
        abort_if(Gate::denies('user_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');
        $golfID = auth()->user()->golfclub_id; 
        
        return response([
            'meta' => [
                'roles'    => Role::get(['id', 'title'])->where('Role.id', '<>', 4),
                'country'  => Country::get(['id', 'name']),
                'golfclub' => Golfclub::get(['id', 'name']),                  
            ],
        ]);
    }
0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

And if you put the where before get so it does that on the database level:

Role::where('id', '<>', 4)->get(['id', 'title'])

Please or to participate in this conversation.