Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Laravel的主布局中的输出为空_Php_Laravel_Layout_Laravel Blade_Master Pages - Fatal编程技术网

Php 使用Laravel的主布局中的输出为空

Php 使用Laravel的主布局中的输出为空,php,laravel,layout,laravel-blade,master-pages,Php,Laravel,Layout,Laravel Blade,Master Pages,我是Laravel的新手,我正在使用Laravel刀片的模板布局继承,这是我的代码,在浏览器上显示hello很简单。但运行此命令后,我的输出显示为空白。浏览器或控制台窗口上未显示任何错误。请帮我找出我的错误 master.blade.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name=

我是Laravel的新手,我正在使用Laravel刀片的模板布局继承,这是我的代码,在浏览器上显示hello很简单。但运行此命令后,我的输出显示为空白。浏览器或控制台窗口上未显示任何错误。请帮我找出我的错误

master.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>master page</title>
</head>
<body>

<div>
    @yield('content')
</div>

</body>
</html>
@extends('master')

@section('content')
<h1> Hello </h1>
@endsection
public function viewmasterpage()
{
    return view('master');
}
Route::get('/masterpage','studentcontroller@viewmasterpage')->name('masterpage');
web.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>master page</title>
</head>
<body>

<div>
    @yield('content')
</div>

</body>
</html>
@extends('master')

@section('content')
<h1> Hello </h1>
@endsection
public function viewmasterpage()
{
    return view('master');
}
Route::get('/masterpage','studentcontroller@viewmasterpage')->name('masterpage');

您将在
studentcontroller
中返回
master
布局,因为您将找不到任何需要返回的
body
,它扩展了
master
布局并包含
Hello


谢谢,它工作了,但是为什么它不能与页面链接一起工作?如果我答对了你的问题,
母版
页面将不会显示任何内容,因为它是空的,它只是其他页面的布局。这正是我要问的,为什么我们没有在控制器中使用母版页链接?好的。母版页或主布局通常用作其他页面布局的模板。例如,您有一个
登录
注册
页面,它们具有相同的html和css,除了表单本身。在这种情况下,您为身份验证页面创建一个主布局
身份验证布局
,两个页面都将扩展它,那么您将返回什么来查看
login
register
页面,或者返回没有任何形式的
auth布局
,当然您将返回
login
register