如何在Laravel中传递数据以进行查看? [英] How to pass data to view in Laravel?
本文介绍了如何在Laravel中传递数据以进行查看?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用return View::make('blog', $posts);
将数据传递到刀片视图中,而在刀片视图中,我试图运行@foreach ($posts as $post)
,但最终出现错误,提示未定义$posts
.
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.
我的问题是$posts
数组将如何调用?
My question is how would the $posts
array be called?
推荐答案
您可以使用with
方法将数据传递到视图.
You can pass data to the view using the with
method.
return View::make('blog')->with('posts', $posts);
这篇关于如何在Laravel中传递数据以进行查看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文