2013-08-16 113 views
0

我宣佈一個公共職能在我的控制器: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錯誤。是否有可能檢索它或?

回答

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); 
} 
+0

仍然得到同樣的錯誤,那'{{$ getdeaths-> player_id}}'高亮顯示。 –

+0

看起來像你的查詢沒有返回行...嘗試dd($ getdeaths)在你的死亡()方法。 –

+0

一切看起來都很好.. http://paste.laravel.com/K3S –