mercredi 20 juin 2018

Conditional Query with WhereBetween Laravel

I've got the following controller function section for a little search block form:

    $manifests = DB::table('carrier_manifests')
        ->join('customers', 'carrier_manifests.carrierOrigin', '=', 'customers.id')
        ->select('carrier_manifests.*', 'customers.customer_name')          
        ->where([
                    ['manifestNumber', 'LIKE', '%' . $manifest . '%'],
                    ['originTerminal','LIKE','%' . $terminal . '%'],
                    ['carrierOrigin', $direction[0], $direction[1]],
                ])
        ->whereNull('deleted_at')
        ->orderBy('dateUnloaded', 'DESC')
        ->whereBetween('dateUnloaded', [$startDate, $endDate])
        ->limit(100)
        ->get();

Every part of it works correctly except for one section, the whereBetween, because of a workflow necessity, sometimes the dateUnloaded in the clause is not filled in for every carrier_manifest, so that means if the dateUnloaded field is empty, it will be left out of the search results.

Are there any suggestions for how to include those results missing the dateUnloaded?

Thanks!



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

Aucun commentaire:

Enregistrer un commentaire