jeudi 22 décembre 2016

How do I filter item(product) with multiple parameter in mongodb / PHP?

I am using mongodb with laravel (php framework).

Using post method I am sending filter parameter to controller function.

ItemController.php

public function search_item(Request $request){

    $item = $request->all();

    $item =  $this->item->search_item($item);

    return response()->json($item,200);

}

Item.php (model file)

public function search_item($item){

$items = new item();

foreach($item as $key => $value){
$items = $items::where($key, '=', $value)->get();
}

}
$items = json_decode(json_encode($pro));
return $items;

If I pass only one parameter then it's give me result perfectly but if I pass more then one parameter it's give me an error.

Non-static method Illuminate\Support\Collection::where() should not be called statically

Let me explain with example :

URL : http://localhost/use_good_store/public/search-item?brand_name=Bajaj

if I post above url it's give me perfect result but if I pass more then one parameter like http://localhost/use_good_store/public/search-item?brand_name=Bajaj&model=Boxer it's give me above error.

any help would be appreciate

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire