How to get the first record with larvel 4 raw queries

How can I get the first record with larvel 4 raw requests.

Something like DB::select('')->first(); does not work and DB::first('')

+8
php laravel laravel-4
source share
4 answers

The fact is that DB: select () returns an array, so you need to:

 DB::select(DB::raw('select * from users'))[0]; 

you also can

 DB::table('users')->first(); 
+20
source share

Like this:

 DB::table('users')->take(1)->get()[0]; 
+1
source share
 DB::table('users')->first(0); 
0
source share

When using eloquence, you can do this:

  $user = User::take(1)->get(); 
0
source share

All Articles