Laravel 4原始查询

时间:2013-08-16 22:18:23

标签: laravel laravel-4

我在控制器中声明了一个公共函数:

public function deaths()
{
    $getdeaths = DB::statement('SELECT * FROM player_deaths ORDER BY time DESC LIMIT 10');
    return View::make('main.latestdeaths')->with('getdeaths', $getdeaths);
}

然后我尝试检索数据:

<td>{{ $getdeaths->player_id }}</td>

但它不起作用。出现Trying to get property of non-object错误。可以检索它吗?

1 个答案:

答案 0 :(得分:0)

尝试

public function deaths()
{
    $getdeaths = DB::select( DB::raw('SELECT * FROM player_deaths ORDER BY time DESC LIMIT 10') );
    return View::make('main.latestdeaths')->with('getdeaths', $getdeaths);
}