查询无效或任何连接问题

I have an issue in my search box, I actually want to show products on a page when anyone searches for the similar product but I am just getting a header and footer not any product.

This is my query in the controller

public function showsearchpage()
{
    $query = Product::where('product_name','LIKE','%$q%');
    return view('search', ['searchbox'=>$query]);
}

and this is my search.blade.php view source code that I want to show up on my search page

 @foreach($searchbox as $query)                   
 <div class="iso-box photoshop branding col-md-4 col-sm-6">
     <div class="portfolio-thumb">
         <img src="images/portfolio-img1.jpg" class="img-responsive" alt="Portfolio">
             <div class="portfolio-overlay">
                 <div class="portfolio-item">
                     <a href="/categoriesViewPost"><i class="fa fa-link"></i></a>
                     <h2>{{$query->product_name}}</h2>
                     <p>{{$query->product_description}}</p>
                 </div>
             </div>
     </div>
</div>
@endforeach

And this is the screenshot that I am getting (I have a similar product in my database of product but still its showing nothing):

ScreenShot of the search page

You forgot get();

public function showsearchpage()
{
    $query = Product::where('product_name','LIKE','%$q%')->get();
    return view('search',['searchbox'=>$query]);
}

problems :

  • '%$q%'
  • ->get();

    public function showsearchpage($q)
    {
    $query = Product::where('product_name','LIKE','%'.$q.'%')->get();
    return view('search',['searchbox'=>$query]);
    

    }

I found out the answer , actually my "q" was not taking input properly . and thanks guys for the help .

public function showsearchpage(Request $request)
{
    $q=$request->input('q');
    $query = Product::where('product_name', 'like', "%$q%")->get();

    return view('search',compact('query'));
}
    }