mardi 22 janvier 2019

Laravel where clause is not working after multiple orWhere clauses?

I am doing this query for search vehicles with model name and type but these where clauses are not at the end after orWhere When I comment or remove these orWhere Clauses then its work.

$models = Vehicle::join('vmodels', 'vmodels.vehicle_id', '=', 'vehicles.id')
    ->join('vehicletypes', 'vehicletypes.id', '=', 'vehicles.vehicletype_id')
    ->join('brands', 'brands.id', '=', 'vehicles.make')
    ->join('companies', 'brands.id', '=', 'companies.name')
    ->select('vehicles.slug as vslug', 'brands.name as brandname', 'vehicles.id as vid', 'vmodels.*', 'vehicletypes.name as vtype', 'companies.status as cstatus')
    ->where('brands.name', 'LIKE', "%{$term}%")
    ->orWhere('vmodels.name', 'LIKE', "%{$term}%")
    ->orWhere('vmodels.year', 'LIKE', "%{$term}%")
    ->orWhere('vehicletypes.name', 'LIKE', "%{$term}%")
    ->orWhere('vehicles.model', 'LIKE', "%{$term}%")
    ->where('companies.status', '=', 1 )
    ->where('vmodels.status', '=', 1)
    ->where('vehicles.status', '=', 1)
    ->paginate(30);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire