Search code examples
phplaravellaravel-blade

How to pass data to view in 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?


Solution

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

    return View::make('blog')->with('posts', $posts);