Laravel:找不到 Layouts.master

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42478785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:25:04  来源:igfitidea点击:

Laravel: Layouts.master not found

phplaravellaravel-5

提问by Feralheart

I built the demosite in Laravel, but I got the following error:

我在 Laravel 中构建了演示站点,但出现以下错误:

ErrorException in FileViewFinder.php line 137: View [layouts.master] not found.(View: /var/www/html/project/laravel/laravel/resources/views/page.blade.php)

FileViewFinder.php 第 137 行中的 ErrorException:未找到视图 [layouts.master]。(视图:/var/www/html/project/laravel/laravel/resources/views/page.blade.php)

The master.blade.php is next to the page.blade.php, both are in resources/views

master.blade.php 在 page.blade.php 旁边,都在资源/视图中

master.blade.php

master.blade.php

<html>
    <head>
        <title>@yield('title')</title>
    </head>
    <body>
        @section('sidebar')
        This is the master sidebar.
        @show
        <div class="container">
        @section('content')
        </div>
    </body>
</html>

page.blade.php

页面.blade.php

@extends('layouts.master')
@yield('title', 'Page Title')
@section('sidebar')
@parent
<p>This is appended to the master sidebar.</p>
@endsection
@section('content')
<h2>{{$name}}</h2>
<p>This is my body content.</p>
@endsection

What goes wrong? I working from this tutorial.

出了什么问题?我从本教程开始工作

回答by EddyTheDove

Try

尝试

@extends('master')

They are both at the viewsroot you said. Or create a directory called layoutsand place master.blade.phpinside.

他们都是views你说的根源。或者创建一个名为的目录layouts并放在master.blade.php里面。

UpdatesIn your master.blade.phpwhere you want your contentto be "injected", do:

更新在您master.blade.php希望content“注射”的地方,请执行以下操作:

@yield('content')
//remove @section('content') because your master does not extends any other layout

The exact same way you did with @yield('title').

与您对@yield('title').

回答by Mayank Pandeyz

When you are using @extends('layouts.master')means your view searches for the masterlayout under resources/views/layoutsdirectory.

当您使用时,@extends('layouts.master')意味着您的视图会搜索目录master下的布局resources/views/layouts

So make sure the masterlayout exist under the resources/views/layoutsdirectory.

所以确保master布局存在于resources/views/layouts目录下。