也许是一个基本问题,但是 - 让我们说有一个带有几个子菜单的下拉菜单:
<a href="{{ URL::route('news') }}">News</a>
<a href="{{ URL::route('articles') }}">Articles</a>
链接到不同的观点:
(news.blade.php, articles.blade.php ...)
index.blade.php如下所示:
@extends('layouts.master')
@section('board')
@include('files.index')
@endsection
路线看起来像这样:
<?php
Route::get('/', [
'as' => 'home',
'uses' => 'PagesController@home'
]);
Route::get('/articles', [
'as' => 'articles',
'uses' => 'PagesController@articles'
]);
Route::get('/news', [
'as' => 'news',
'uses' => 'PagesController@news'
]);
和控制器:
class PagesController extends Controller
{
public function home()
{
return view('files.index');
}
public function articles()
{
return view('files.articles');
}
public function news()
{
return view('files.news');
}
}
问题是,&#39;董事会&#39; section应仅在开头加载index.blade,但在单击菜单中的链接后替换其内容。 谢谢你的帮助。
答案 0 :(得分:-1)
创建pages.blade.php视图并相对于它创建文件夹&#34; pages&#34; with articles.blade.php,news.blade.php,home.blade.php等。
pages.blade.php:
@extends('layouts.master')
@section('board')
@include('pages.'.$page_file)
@endsection
这是你的控制器:
class PagesController extends Controller
{
public function home()
{
return view('pages', ['page_file' => 'home']);
}
public function articles()
{
return view('pages', ['page_file' => 'articles']);
}
public function news()
{
return view('pages', ['page_file' => 'news']);
}
}