刀片不工作(拉拉威尔),为什么什么都没有显示


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

刀片不工作(Laravel),为什么什么都没有显示?

1.show.blade.php

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

2.book/show.blade.php

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

显示的代码没有任何问题。问题出在你的路线上。以下是您的路线片段:

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

Route::resource('book')创建与'book/{book}'完全相同的URI,因此它覆盖第一个URI。换句话说,你的关闭永远不会被触发。你有几个选择。

  1. 不要使用Route::resource。我喜欢明确我的路线
  2. 把你的Route::get('book/{book}放在Route::resource之后。这也行得通
  3. 删除Route::get('book/{book}'),只需将代码添加到BookControllershow方法中即可

这3个选项中的任何一个都可以。如果您喜欢使用Route::resource,我建议您选择#3。否则,我将使用选项#1。在我看来,选项#2和超越其他路线并不是一种很好的方式。

根据您在pastebin中的代码。

return view('comment.show', ['comment' => $comment]);更改为return view('book.show', ['comment' => $comment]);

编辑

另一个问题是你的章节以@endsection结尾。它将是@stop

你的代码应该是这样的:

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