如何在 Laravel 中传递数据以查看? [英] How to pass data to view in Laravel?

查看:35
本文介绍了如何在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆