Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass data to view in Laravel?

Tags:

php

laravel

Im passing data to my blade view with return View::make('blog', $posts); and in my blade view I'm trying to run an @foreach ($posts as $post) I end up with an error saying that $posts isn't defined.

My question is how would the $posts array be called?

like image 252
Sam Pettersson Avatar asked Aug 20 '13 17:08

Sam Pettersson


People also ask

How do I move data from one page to another in Laravel?

You can send an ID (variable value) to another page in Laravel using the route method in the anchor tag in the view file by passing the variable to it. You have to just pass data from route to controller and after controller to another view page.

How do I load a view in Laravel?

Loading a view in the controller is easy. You just need to add `view('viewname')` method while returning from the controller method. `view()` is a global helper in Laravel. In this method, you just need to pass the name of the view.


1 Answers

You can pass data to the view using the with method.

return View::make('blog')->with('posts', $posts); 
like image 119
Mostafa Elgaafary Avatar answered Oct 14 '22 12:10

Mostafa Elgaafary