ethar
1 month ago

Multi Parameter in Search 'GET'

Posted 1 month ago by ethar

i try to make multi search parameter, i check if request->any have value or not, if have value shot match that value , if not should not append it in search

public function search(Request $request)
    {
        $product = Products::select('id', 'cats_id', 'brands_id', 'name_ar', 'admins_id')
            ->with('admins:id,name')
            ->with('cats:id,cats_name_ar')
            ->with('brands:id,brands_name_ar')
            ->paginate(10);
        if ($request->s !== null) {
            $product->where('name_ar', 'LIKE', "%{$request->s}%");
        }
        if ($request->discount == '1') {
            $product->where('discount', '!=', null);
        }
        return view('admin.product.indexproduct', compact('product'));
    }

but not worked, all value returned, my condition ignored, plz how to do that.

Please sign in or create an account to participate in this conversation.