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

时间:2016-03-17 07:46:48

标签: php laravel laravel-routing 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));
}

1 个答案:

答案 0 :(得分:5)

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

如果您需要将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
相关问题