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?
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.
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.
You can pass data to the view using the with
method.
return View::make('blog')->with('posts', $posts);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With