Remove an object from the collection in Laravel?

1

I have the following, I am getting all the clients that belong to a user with eloquent, these clients show them in a select in the blade view, my problem is that in the clients table there is a field that specifies if the client is already is assigned or not, I need to remove from the collection of clients those that are already assigned, so that in the blade view only show me those that are not assigned I am trying this way:

public function getClients()
    {
        //Con esto obtenemos todos los clientes que pertenezcan al usuario autenticado
        $client = Auth::user()->clients()->get();

        foreach ($client as $clients) {
            if ($clients->community =='asigned' && $clients->account_director == 'asigned') {
                $client->pull($clients);
            }

        }

        dd($client);

        return $client;
    }

but I get this error array_key_exists (): The first argument should be either a string or an integer ", in what way could the clients that are already assigned be removed from the collection?

    
asked by Kevin Burbano 29.08.2018 в 23:51
source

1 answer

1

If I understand what you need is:

  

"Remove from the client collection those that are already   assigned "

I'm a little confused about the code you put in, but I think what you have to do is:

public function getClients()
{
    $clients = Auth::user()->clients->where('community', '!=', 'asigned')
                                    ->where('account_director', '!=', 'asigned');

    return $clients;
}

I hope my solution will be helpful.

    
answered by 30.08.2018 / 01:38
source