从Laravel中的Module加载页眉和页脚 [英] Load header and footer from Module in Laravel
问题描述
我已经在Laravel中创建了一个模块,并使用该模块上的视图即时通讯,我的结构是这样的:
I have created a module in Laravel and im using views on that module, my structure is this:
模块
-> MyModule
->->Controllers
->->Views
->->->MyModule.blade.php
但是我在资源-> views-> layouts-> base.blade.php
But i have the headers and footer done on resources->views->layouts->base.blade.php
那么我怎么称呼这个,这样我就可以在所有模块中使用相同的基本布局?可以在Laravel 5上使用吗?
So how can i call this one so i can use the same base layout in all modules? it is possible on Laravel 5?
已经尝试过
@include('layouts.base')
但我正在得到
尝试获取非对象的属性(视图:... resources\views\layouts\base.blade.php
Trying to get property of non-object (View: ... resources\views\layouts\base.blade.php
谢谢
推荐答案
blade的结构相对于 views
文件夹的相对位置资源
文件夹。
The structure of blade is relative to the views
folder in the the resources
folder.
因此使您的 @include()
具有这样的结构:
Thus making your @include()
have a structure like the this:
@include('DIRECTORY.BLADE')
,您可以使用 @yield()
@yield('YIELD_FIELD_NAME')
如果您尝试从该布局中扩展刀片范围,则可以在刀片文件的顶部调用该扩展名。
If you are trying to have blades extent from that layout you would call that at the top of the blade files you want to extend off it.
@extends('DIRECTORY.BLADE')
这是一个示例刀片文件,如果布局包含 @yield( 内容)
标签。
This is an example blade file that can extend your layout if your layout contains the @yield('content')
tag in it.
example.blade.php
example.blade.php
@extends('layouts.base')
@section('content')
YOUR BLADES HTML/CONTENT
@endsection
https://laravel.com/docs/5.4/blade#defining-a-layout
如何向控制器添加Auth中间件:
How to add Auth middleware to controller:
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
Here is an example Controller: https://github.com/jeremykenedy/laravel-auth/blob/master/app/Http/Controllers/UsersManagementController.php
以下是使用该控制器的视图示例:
https://github.com/jeremykenedy/ laravel-auth / blob / master / resources / views / usersmanagement / show-user.blade.php
Here is an example of a view that uses that controller: https://github.com/jeremykenedy/laravel-auth/blob/master/resources/views/usersmanagement/show-user.blade.php
以下是视图使用的模板示例:
https:/ /github.com/jeremykenedy/laravel-auth/blob/master/resources/views/layouts/app.blade.php
Here is an example of the template that view uses: https://github.com/jeremykenedy/laravel-auth/blob/master/resources/views/layouts/app.blade.php
这里是以上示例的路由文件:
https: //github.com/jeremykenedy/laravel-auth/blob/master/routes/web.php
Here is the routing file for the above examples: https://github.com/jeremykenedy/laravel-auth/blob/master/routes/web.php
这篇关于从Laravel中的Module加载页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!