Laravel - Blade 未在浏览器中加载

Laravel - Blade not loading in the browser

我有一个新的 Laravel 项目似乎无法正确加载 Blade。

我查看了 Laravel.com 上的文档,观看了 Laracasts 上的视频,并尽可能多地扫描了 Whosebug,但我仍然无法弄清楚。你能帮忙吗?!

好的,这是我目前的情况:

Web.php

Route::get('/', [
    'uses' => 'RentsController@index',
    'as' => 'layouts.index'
    ]);

RentsController.php

public function index()
{
    $rents = DB::table('rents')
        ->orderByDesc('price')
        ->get();
    return view('layouts.index', ['rents' => $rents]);
}

index.blade.php

<div class="container">
    <p>test</p>
    @yield('content')
</div>

search.blade.php

@extends ('layouts.index')

@section ('content')
    <p>title</p>
    <h1>test</h1>
    <ul>
        @foreach ($rents as $rent)
        <li>{{ $rent->price }}</li>
        @endforeach
    </ul>
@endsection

文件结构:

视图 -> 布局 -> index.blade.php 观看次数 -> search.blade.php

因此,每当我将 @section('content') 中的代码直接粘贴到文件 index.blade.php 中时,它都能完美运行。但是,正如我现在所拥有的,search.blade.php 中没有任何内容出现在浏览器中,也没有错误。

知道它是什么吗?

谢谢你们!!我非常感谢您提供的任何帮助、提示、问题和评论。 :)

其实我不知道你为什么要在路由和控制器中指定你的布局。在控制器中 return 您的页面模板就足够了:

Web.php

Route::get('/','RentsController@index');

RentsController.php

public function index()
{
    $rents = DB::table('rents')
        ->orderByDesc('price')
         ->get();
    return view('search', compact('rents'));
}

在使用布局时,使用@extends ('layouts.index')即可,模板会识别。