search api laravel code example

Example 1: wherehas laravel search

->whereHas('translation', function ($query) use ($name){
                    $query->where('name', 'like', $name);
                }, '>=', 10)

Example 2: laravel create search

public function index(){
      // // we need to show all data from "blog" table
      // $blogs = Blog::all();
      // // show data to our view
      // return view('blog.index',['blogs' => $blogs]);

      $search = Request::get('search');
      $blogs = Blog::where('title','like','%'.$search.'%')->orderBy('id')->paginate(6);
      return view('blog.index',['blogs' => $blogs]);
    }

Tags:

Php Example