传递数据以在Laravel中查看 [英] Passing data to view in laravel

查看:68
本文介绍了传递数据以在Laravel中查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

    $input = Input::all();
    $this->agro->create($input);

    $alldata = $this->agro->all();

    return View::make('agro.showdata',['myalldata'=>$alldata]);

在这里,当我返回$alldata时,将显示数据库中的所有数据.我猜这里所有数据都存储在$alldata变量中,该变量将传递给变量myalldata中的showdata视图文件. /p>

现在在myalldata中时,如果无法访问数据,它将作为

<h1>DIsplaying data </h1>

但是当我尝试显示数据时,它给出了错误Whoops, looks like something went wrong

<h1>Displaying data from database<h1>

{{ $myalldata->title }}

请帮助显示数据库中的数据.

另一件事,每当出现问题时,都会报错.​​Whoops, looks like something went wrong.如何调试laravel以了解问题出在哪里?

解决方案

似乎$ myalldata是元素数组.要访问每一个,您需要在视图中使用一个for循环,如下所示:

@foreach($myalldata as $row)
    <div>{{{ $row->title }}}</div>
@endforeach


您可以通过修改应用程序的app/config/app.php文件并替换来确定是否显示完整的错误跟踪

'debug' => false,

使用

'debug' => true,

请记住,在生产环境中(客户端可以访问站点时),您将要禁用调试模式.

I have the following code

    $input = Input::all();
    $this->agro->create($input);

    $alldata = $this->agro->all();

    return View::make('agro.showdata',['myalldata'=>$alldata]);

Here when I return $alldata, all data from database is displayed.I guess here all the data is stored in $alldata variable which we are passing to the showdata view file in the variable myalldata.

Now when in myalldata, if data is not accesses it works as

<h1>DIsplaying data </h1>

But when I try to display data, it gives error Whoops, looks like something went wrong ie

<h1>Displaying data from database<h1>

{{ $myalldata->title }}

Please help display the data from database.

Another thing, every time something is wrong, it gives error Whoops, looks like something went wrong.How to debug laravel to know where things are going wrong?

解决方案

It appears that $myalldata is an array of elements. To access each one, you'd need to use a for-loop, like such, in your view:

@foreach($myalldata as $row)
    <div>{{{ $row->title }}}</div>
@endforeach


You can determine whether to display the full error trace by modifying your application's app/config/app.php file, and replacing

'debug' => false,

with

'debug' => true,

Keep in mind that, in a production environment (when clients can access the site), you'll want to disable debug mode.

这篇关于传递数据以在Laravel中查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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