簡體   English   中英

如何從Laravel 5.2中的一個函數返回兩個視圖

[英]How to return two views from One Function in Laravel 5.2

我的問題很難解釋,但我會盡力清楚地闡述它。 我有一個StoreController,它包含用於顯示單頁產品數據的單個show($ id)函數。 這個函數有一個return語句,它是( return View::make('store.show')->with('product', product::find($id)); )但我還有一個其他視圖,即store.category我希望在哪里顯示產品的類別明智結果,現在該如何實現? 我想到的一種方法是使用這個show函數並返回它( return View::make('store.category'); )但是在SHOW函數中已經有一個返回!

PS:使用資源控制器和Laravel 5.2,如果需要其他任何東西,請在評論中提及我盡快添加它!

public function show($id) {
        return View::make('store.show')->with('product', product::find($id));
}

你不能這樣做。 您可以做的是使用Blade視圖系統包含任意數量的視圖 良好的視圖繼承是您通常想要的。

如果您需要將store.category視圖包含在此特定頁面中,您可以執行以下操作:

public function show($id) {
        return View::make('store.show')->with('product', product::find($id))->with('showStore', true);
}

在一個視圖中:

@if(showStore)
@include('store.category')
@endif

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM