Eloquent get()

use App\Post;
Route::get('/findwhere', function(){
	$posts = Post::where('id', 1)->orderBy('id', 'desc')->take(1)->get();
	return  $posts;

});

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

確かにraw queryのselect * fromよりもeasy to understand
DB::select(‘select * from posts where id = ?’, [1]);

FindOrFail()とも書ける

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

	$posts = Post::findOrFail(4);
	return $posts;

});