Support the ongoing development of Laravel.io →
posted 10 years ago
Views
Last updated 2 years ago.
0

These two pieces of code are equivalent:

$viewData = array('foo' => $bar);
return View::make('x', $viewData);
return View::make('x')->with('foo', $bar);

So in your second example, $viewData would have to have a key of 'viewData' to be equivalent to the first one.

Last updated 2 years ago.
0

So

return View::make('x')->with('foo', $bar);

only makes sense when i wanna send only one array/value to the View?

And if i have several arrays i do this?

$bar['city'] = array();
$bar['music'] = array();
$bar['location'] = array();
return View::make('x', $bar);

Instead of several with's like this:

return View::make('x')->with('city', array())->with('music', array())->with('location', array());

What's the best practice?

Thanks, Sharping

Last updated 2 years ago.
0

Sharping said:

So

return View::make('x')->with('foo', $bar);

only makes sense when i wanna send only one array/value to the View?

And if i have several arrays i do this?

$bar['city'] = array(); $bar['music'] = array(); $bar['location'] = array(); return View::make('x', $bar);

Instead of several with's like this:

return View::make('x')->with('city', array())->with('music', array())->with('location', array());

What's the best practice?

Thanks, Sharping

I generally the array method because it's less verbose, but it comes down to personal preference.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Sharping sharping Joined 28 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.