Designlenta Gogo
Designlenta Gogo

Reputation: 307

Blade not working (Laravel), why is nothing shown?

Blade not working (Laravel), why is nothing shown?

1.show.blade.php

@extends('book.show')
@section('comment')
    Yuup!
@endsection

2.book/show.blade.php

<ul class="cols">
    <li>
       @yield('comment')
    </li>
</ul>

Upvotes: 0

Views: 488

Answers (2)

Thomas Kim
Thomas Kim

Reputation: 15931

Nothing was wrong with the displayed code. The problem was in your routes. Here is a snippet from your routes:

Route::get('book/{book}', function () {
    $comment = 'Hello';
    return view('comment.show', ['comment' => $comment]);
});

Route::resource('book', 'BookController');

Route::resource('book') creates the exact same URI as 'book/{book}' so it overrides the first one. In other words, your closure is never triggered. You have several options.

  1. Don't use Route::resource. I like to be explicit with my routes.
  2. Put your Route::get('book/{book} after the Route::resource. This would work too.
  3. Remove Route::get('book/{book}') and just add your code inside your BookController classes show method.

Any of these 3 options will work. I suggest option #3 if you like using Route::resource. Otherwise, I would work with option #1. Option #2 and overriding other routes and such isn't a very nice way of going about things in my opinion.

Upvotes: 1

smartrahat
smartrahat

Reputation: 5609

According to your code in pastebin.

Change return view('comment.show', ['comment' => $comment]); to return view('book.show', ['comment' => $comment]);

EDIT

Another problem is you end your section with @endsection. It will be @stop.

Your code should look like this:

@extends('book.show')
@section('comment')
    Yuup!
@stop

Upvotes: 0

Related Questions