mercredi 29 novembre 2017

How to filter results in Laravel using Eloquent Models

I am attempting to use the following

$orders = \App\Order::with([
    'Customer' => function ($query) use ($filterFirst, $filterLast, $filterstate)
    {
        if($filterFirst)
        {
            $query->where('customers.first', 'LIKE', "{$filterFirst}%");
        }
        if($filterLast)
        {
            $query->where('customers.last', 'LIKE', "{$filterLast}%");
        }
        if ($filterstate)
        {
            $query->where('customers.state', '=', $filterstate);
        }
    }

However, when I run ->get on $orders I get the entire table of orders, and I just want to get the orders that match the Customer Filters...

Any ideas on how I can accomplish this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2AkJzbZ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire