Sometimes one may want to load a View with some PHP data passed to it and store it in a variable inside the Controller’s action. This rendered view data might be later passed to another view which is finally loaded and dumped to the user’s screen.
Doing so in Laravel is pretty simple, let me show you how:
What's the one thing every developer wants? More screens! Enhance your coding experience with an external monitor to increase screen real estate.
$view = View::make('my_view', ['name' => 'Rishabh']); $contents = (string) $view; // or $contents = $view->render();
We basically make a view that is to be returned to the browser and store the object in a variable called $view
. Then we convert that object to its string representation which is basically the contents of the view (with all the dynamic PHP data injected) or call the render
method on the object to return the same content.
Hope that helps!
Thanks man.. made my day.