0

I have a list of ids I want to use to get items out of my database table.

    $permittedClientIds = UsersClientsBridge::where('users_id', auth()->user()->id)->pluck('clients_id')->all();
    $firstPermittedClientIds = UsersClientsBridge::where('users_id', auth()->user()->id)->pluck('clients_id')->first();

    $clientsQuery = Clients::where('id', $firstPermittedClientIds);

    foreach($permittedClientIds as $clientId) {
       $clientsQuery->orWhere('id',$clientId);
    }

    $clientsQuery->get();

    return view('client.clients', [
        'clients' => $clientsQuery
    ]);

this $permittedClientIds contains 10 and 48. When I manually write the orWhere query it returns the expected output but this is retuning 0 results.

I'm not sure if I need $firstPermittedClientIds I only use it so I can initialize my query.

  • Can you explain the problem you're trying to solve not the solution you think you want. I suspect https://stackoverflow.com/questions/22758819/laravel-wherein-or-wherein might be useful. – 9bO3av5fw5 May 21 '20 at 15:30

1 Answers1

1

Solved using whereIn

$permittedClientIds = UsersClientsBridge::where('users_id', auth()->user()->id)->pluck('clients_id')->all();
$clientsQuery = Clients::whereIn('id', $permittedClientIds)->get();
return view('client.clients', [
    'clients' => $clientsQuery
]);