0

so i am trying to implement search bar, in the blog i'm working on and when i search it gives me undefined variable post in search.blade.php and i have tried all i can . please help

heres my search.blade file

@extends('layouts.main')    
@section('content')     
    <div class="col-lg-8">     
        @foreach($posts as $post)
            <h2>
                <a href="/store/{{ $post->id }}">{!! $post->title !!}</a>
            </h2>
            <p class="lead">
                by <a href="index.php">{!! $post->author !!}</a>
            </p>
            <p><span class="glyphicon glyphicon-time"></span> Posted on {!! $post->created_at !!}</p>
            <hr>
            <a href="/store/{{ $post->id }}">{!! Html::image('/img/posts/'. $post->image, $post->title, array('style'=>'width: 675px; height:225px;')) !!}</a>{
            <hr>
            <p>{!! $post->short_desc !!}</p>
            <a class="btn btn-primary" href="/store/view/{{ $post->id }}">Read More <span class="glyphicon glyphicon-chevron-right"></span></a>

            <hr>
         @endforeach   
     </div>            
@endsection

And the controller function

public function getSearch(Request $request) { 
    $keyword = $request->input('keyword'); 
    $categories = Category::all(); 
    if( $keyword != ""){ 
        return view('store.search')->with('posts', Post::where('title', 'LIKE', '%'.$keyword.'%')->get()) 
            ->with('keyword', $keyword) 
            ->with('categories', $categories); 
     } 
     else { 
         return redirect('/') ; 
     } 
}
zahid hasan emon
  • 6,023
  • 3
  • 16
  • 28

0 Answers0