Raw SQL Queryでselect * from

DB classでselectして$resultに格納する
あれ、exceptionになる。。

Route::get('/read', function(){
	$result = DB::select('select * from posts where id = ?', [1]);
	return $result->title;

});

あれ、これなら上手くいく

Route::get('/read', function(){

	$results = DB::select('select * from posts where id = ?', [1]);

	foreach($results as $post){
		return $post->title;
	}

});

debugしながらやらないと駄目のようです。

Route::get('/read', function(){
	$results = DB::select('select * from posts where id = ?', [1]);
	return $results;
});

[{“id”:1,”title”:”php with laravel”,”content”:”Laravel is the best thing that happen to PHP”,”created_at”:null,”updated_at”:null,”is_admin”:0}]

ここまでくれば、update, deleteの想像がつきます。