SHARE
TWEET

Search Controller

a guest Aug 23rd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function search(Request $request)
  2.     {
  3.         $search = $request->input('search');
  4.         $productsearch = Products::orderBy('created_at','desc')->where('products_name', 'like', '%'. $search .'%')
  5.         ->orWhere('unit_price', 'like', '%'. $search .'%')->orWhere('model', 'like', '%'. $search .'%')
  6.         ->orWhereHas('suppliers', function($q) use($search) {
  7.             $q->where('company_name', 'like', '%' . $search . '%');
  8.         })->orWhereHas('category', function($q) use($search) {
  9.             $q->where('category', 'like', '%' . $search . '%');
  10.         })->paginate(5);
  11.         $i = 0;
  12.         foreach($productsearch as &$products){
  13.            
  14.             $product[$i] = str_replace($search,"<span class='highlight'>$search</span>",$products);
  15.             $i++;
  16.                      
  17.           }  
  18.         //   dd($products);
  19.         return view('products.index',compact('product'));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top