如何在 Laravel 5.2 中的一个函数中返回两个视图


How to return two views from One Function in Laravel 5.2

我的问题有点难解释,但我会尽量干净利落地阐述它。我有一个商店控制器,其中包括用于显示单页产品数据的单显示($id)功能。这个函数有一个返回语句,它是(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));
}

你不能这样做。您可以做的是使用刀片视图系统包含任意数量的视图。良好的视图继承是你通常想要的。

如果您需要将 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