2017-08-20 26 views
2

大家好,我想加載shopReq.blade.php文件在master.blade.php,我成功地做到了這一點。但是當我加載modals.blade.php文件在shopReq.blade.php它不包括在內。我在這裏做錯了什麼?請幫忙。@yield,@laction在Laravel

master.blade.php(在視圖/佈局):

<html> 
    <body > 
      @yield('content') 
    </body> 
</html> 

shopReq.blade.php(在視圖中)

@extends('layouts.master') 
@section('content') 
<h1>Hello I am in shopReq.blade.php 
@yield(content) 
@endsection 

modals.blade.php(在視圖中)

@extends('shopReq') 
@section('content') 
<h1>Hello I am in modals.blade.php 
@endsection 

web.php:

Route::group(['middleware' =>['web']], function() 
    { 
    Route::get('/', function() { 
     return view('welcome'); 
    })->name('home'); 
}); 
+0

您是否收到任何錯誤? –

+0

@ B.Desai No.沒有錯誤。我想'modals.blade.php'在'shopReq.blade.php'上。但我這樣做沒有成功。 –

+0

哪個'view'你最終打電話?在你的問題添加路線和查看調用代碼。你在這種情況下添加了'welcome'視圖代碼,而不是實際的問題代碼 –

回答

0

問題出在類似的名字。 你不能yield('content')section('content')裏面,你將不得不重新命名其中一組。

因此,無論是在shopReq中更改master和section中的產量,還是更改模式中shopReq中的產量。

1

正如用戶milo526所說。

您有@yield('content')兩次。

對於任何刀片指令(收率部分,組件......)

如果存在括號內將被覆蓋一個相同的名稱。

而且我現在有現貨,你沒有對你的第二個產量引號 '':

@yield(content) 
2

上shopReq.blade.php與@include('modals')

modals.blade.php更換@yield(content)

<h1>Hello I am in modals.blade.php</h1> 
航線上

return view('shopReq');