-3

This is postController.php code:

public function index()
{


    $posts = post::orderBy('created_at', 'DESC')->get();


    return view('posts.index', compact('posts'));

}

Also I make Route ( web.php ):

Route::resource('post','PostController');

This is view ( index.blade.php ) code:

@section('content')

    @foreach($posts as $post)

    <div class="panel">
       <div class="panel-heading">
           <h3>{{ $post -> title }}</h3>
       </div>

       <div class="panel-body">
              {{ $post -> body }}
       </div>
    </div>

    @endforeach

@endsection

After all of that I cannot find the error why my result doesn't display from data base

https://i.stack.imgur.com/LhZ9a.png

This tables should be displayed from database

https://i.stack.imgur.com/GZaJ6.png

When I try another way the result was displayed u can see that when I write at postController.php code:

public function index()
{

    $posts = post::orderBy('created_at', 'DESC')->get();

    return $posts;   

}

It showed from data base but there is also problem here ! Why the code is not displayed in a neat way in browser

https://i.stack.imgur.com/xnUj0.png

O'Neil
  • 3,790
  • 4
  • 16
  • 30

1 Answers1

0

try print post variable on post.index.blade using {{dd($posts)}}. if your getting $posts variable on blade than everything fines.if not than dd("some meassage") into your index() to check if your index method actually get call.

if your index() method does not print dd("some message") than in terminal type php artisan route:list to check if your routes is prefix with something.

shubham singh
  • 400
  • 2
  • 7