laravel compact() and ->with()
I was able to use
return View::make('myviewfolder.myview', compact('view1','view2','view3'));
I don't know if it's because I am using PHP 5.5 it works great :)
The View::make
function takes 3 arguments which according to the documentation are:
public View make(string $view, array $data = array(), array $mergeData = array())
In your case, the compact('selections')
is a 4th argument. It doesn't pass to the view and laravel throws an exception.
On the other hand, you can use with()
as many time as you like. Thus, this will work:
return View::make('gameworlds.mygame')
->with(compact('fixtures'))
->with(compact('teams'))
->with(compact('selections'));
I just wanted to hop in here and correct (suggest alternative) to the previous answer....
You can actually use compact in the same way, however a lot neater for example...
return View::make('gameworlds.mygame', compact(array('fixtures', 'teams', 'selections')));
Or if you are using PHP > 5.4
return View::make('gameworlds.mygame', compact(['fixtures', 'teams', 'selections']));
This is far neater, and still allows for readability when reviewing what the application does ;)
Laravel Framework 5.6.26
return more than one array then we use compact('array1', 'array2', 'array3', ...)
to return view.
viewblade
is the frontend (view) blade.
return view('viewblade', compact('view1','view2','view3','view4'));