在Laravel 5中包含基于href参数的视图


include view based on href parameter in Laravel 5

可能是一个基本问题,但是-让我们说有一个下拉菜单与几个子菜单:

<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');
    }
}

问题是,'board'部分应该加载索引。刀片只在开始,但替换其内容后,从菜单的链接被点击。谢谢你的帮助。

创建pages.blade.php视图,并在其上创建文件夹"pages",其中包含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']);
    }
}