1
votes
           **after clicking "read more" i want to show a single post**

               <a href="{{ URL::to('single/blog/'.$post->id) }}" class="btn btn-primary 
                    float-right">Read More &rarr;</a>

             ** **the route is****
               
      Route::get('single/blog/{id}','Web\Site\HomeController@show');

         **the controller is**
          public function show($id)
              {
               $posts = Post::findOrFail($id);
               return view('site.home.singleblog',compact('posts'));
                }

          ****the single section is****
               
  • @foreach($posts as $post) <img class="img-responsive" src="{{asset("uploads/posts/$post->id/image/$post->image") }}" alt=""
{{ $post->name }} {{$post->description}} @endforeach

2

2 Answers

0
votes

Your variable $posts is a single Post instance from Post::findOrFail($id) (where $id is coming from a route parameter, so a single value). You don't want to be iterating an instance of a Model. Use it in your view like a single model instance not a collection.

public function show($id)
{
    view('site.home.singleblog', [
        'post' => Post::findOrFail($id),
    ]);
}

Then in the view just remove the @foreach and @endforeach.

-1
votes

Try this:

{{ $post['name'] }} {{$post['description']}}

If you fetched $posts successfully, it should work. The error says $post is not an object but you are using object syntax to get value by key. So use array syntax.