Tuesday, March 14, 2017

Condition in a search query doesn't work

I have a search query fonction who seems to not work with the last condition . (->where('structure_id' , '=' , $mastructure);

I fact when i run the query i get also the other licences from other "structure_id "

here my search controller

 public function getLicenciesStructure(Request $request){

        $mastructure = Auth::user()->structure->id ;

        $search = $request->get('recherche');
        if ($search) {
            $query = Licencies::Where('lb_nom', 'like', "%$search%")->orWhere('num_licence' , 'like'  , "%$search%")->where('structure_id' , '=' , $mastructure);
        }

        $licenciestructures = $query->paginate(10)
            ->appends(['recherche' => $search]);

        return view('licencie_structure/index' , compact('licenciestructures' , 'mastructure'));


    }

Someone have an idea why the query display also the other items from other structure_id ? thanks a lot in advance



via Mathieu Mourareau

Advertisement