仅在Live Server上的未定义变量Error Laravel

时间:2015-02-25 16:13:20

标签: php laravel

我正在开发一个自定义的Laravel项目。

我收到以下错误:

Undefined variable: count_pandding (View: /domains/web4/html/manager/app/views/admin/home.blade.php)

但奇怪的是这个错误没有在localhost中显示,只能在生活服务器中完美运行。

我尝试过以两种方式传递变量:

public function home()
{

    $count_pandding = \Postjob::where('approve',0)->get()->count();
    $count_disapprove = \Postjob::where('approve',2)->get()->count();
    $count_approve = \Postjob::where('approve',1)->get()->count();
    $count_expire = \Postjob::where('approve',3)->get()->count();

    return View::make('admin.home',  compact('count_pandding','count_disapprove','count_approve','count_expire'));

}

和第二路

 public function home()
{

    $data['count_pandding'] = \Postjob::where('approve',0)->get()->count();
    $data['count_disapprove'] = \Postjob::where('approve',2)->get()->count();
    $data['count_approve'] = \Postjob::where('approve',1)->get()->count();
    $data['count_expire'] = \Postjob::where('approve',3)->get()->count();

    return View::make('admin.home',$data);
}

它在Life Server中都不起作用!但在Localhost中完美运行。

1 个答案:

答案 0 :(得分:0)

请查看Larvel Response

make的第二个参数是一个带键值绑定的数组。我觉得很奇怪,这是在你的本地机器上工作。

尝试

return View::make('admin.home', [
   'count_pandding' => $count_pandding,
   ...
]);

Or

return View::make('admin.home')->withCountPannding($count_pannding); 
//this becomes $countPannding in your view

更新

return View::make('admin.home')->with($keyValueArray); 
//should also translate into $key inside the view.