打印控制器变量以查看Laravel

时间:2014-11-26 04:10:49

标签: php laravel web orm eloquent

在这里工作几个小时,我想在视图中打印控制器变量。这是我的代码:

控制器:

        $mydate=Carbon::now()->addHours(8);
        $newdate=$mydate->toDateString();

        $mydata = DB::table('attendances')->where('date_only', '=', $newdate)->get();



        return View::make('Home')->with($mydata);

这是我的观点

       <div> {{$mydata}} </div>

我刚刚收到此代码的错误

2 个答案:

答案 0 :(得分:3)

试试这个

$mydate=Carbon::now()->addHours(8);
    $newdate=$mydate->toDateString();

    $mydata = DB::table('attendances')->where('date_only', '=', $newdate)->get();



    return View::make('Home',['mydata' => $mydata]); //just a different way to send vars to view

视图:

而不是

<div> {{$mydata}} </div>

使用此

<div> {{print_r($mydata)}} </div>

答案 1 :(得分:1)

你试过吗

<div> {{ print_r($mydata->toArray())}} </div>
 //or
<div> {{ print_r($mydata)}} </div>
//try this to know if you have got data in your $mydata
<div> {{ $mydata[0]->id }} </div>  // id- a field name can change if u dont have one

或在您的控制器中尝试此操作

$this->content = View::make('Home', array('mydata' => $mydata));