mardi 29 novembre 2022

Laravel 8 - search paginate ( withQueryString ) not working on table when searching NUMBERS on row integer

i can't search when it comes to searching NUMBERS on row int (price), but when searching like String number on row string (name) it's working fine

like this in my table row here is my Product table

category_id
"56"
user_id
"1"
name
"555"
description
"fruit"
price
555

when i am searching the name row "555" it's working fine beacuse its a string. but when it comes to price i can't search it because it's int

here is my code for controller searching

public function index(Request $request){
    $user = Auth::user()->id;
    if($request->search){
        $search = $request->search;
        $products = Products::with('category')
        ->where('name','like',"%$search%")
        ->orWhere('price','like',"%$search%")
        ->where('user_id',$user)->paginate(10);
    }else{
        $products = Products::with('category')->where('user_id',$user)->paginate(10);
    }
      return view('client.product.index',['products'=>$products]);
}

here is my blade

    <form class="w-full" action="">
        <i class="fa fa-search"></i>
        <input placeholder="Search"  type="search" name="search">     
        <button type="submit">Search</button>
    </form>

@foreach ($products as $product)
    <p></p>
    <p></p>
@endforeach



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire