返回多个变量以在Laravel中查看的最佳方法 [英] Best Way to return multiple variables to view in laravel
本文介绍了返回多个变量以在Laravel中查看的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个动作方法,它的体内有多个类似这样的变量:-
I have an action method which has in its body multiple Variables something like this :-
$bus=Bus::all();
$user=User::all();
$employer=employer::all();
将这些变量对象返回到视图的过程正在使用这样的代码
what am doing to return those variables objects to the view is using code like this
return view('create')->with(compact('bus', $bus))->with(compact('user', $user))->with(compact('employer', $employer));
有没有一种方法或某种方法可以立即返回此对象,而无需所有此类代码,例如
is there a way a method or something to return this objects at once without the need for all of this code some thing like
return view('create')->($user,$bus,$emp);
只是我想要的例子.
推荐答案
您可以创建这样的数组
$data['bus']=Bus::all();
$data['user']=User::all();
$data['employer']=employer::all();
return view('create',['data'=>$data]);
这篇关于返回多个变量以在Laravel中查看的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文