2017-05-30 109 views
-1

我想在我的index.blade.php中包含頁眉和頁腳文件。我把所有的標題內容放入了footer.blade.php文件中的header.blade.php文件和頁腳內容。以下是我的控制器:Laravel:包括頁眉和頁腳文件不起作用

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

class GeneralController extends Controller 
{ 


    public function header() 
    { 
     return view('header'); 
    } 

    public function footer() 
    { 
     return view('footer'); 
    } 

    public function index() 
    { 
     $this->header(); 
     return view('index'); 
     $this->footer(); 
    } 
} 

我在加載主內容之前調用頭函數。和加載主要內容後的頁腳文件。我在Codeigniter中這樣做,它在那裏工作得很好。但它不在Laravel工作。請幫忙。

回答

2

這樣做是行不通的。 $this->footer();從來沒有執行過,因爲它在return之後,並且你沒有對$this->header()的結果做任何事情。

index.blade.php文件應該做@include('header')和你想讓他們出現@include('footer')

https://laravel.com/docs/5.4/blade#including-sub-views