How can i get the first record with laravel 4 raw queries.
Something like DB::select('')->first();
is not working
neither did DB::first('')
Using Laravel Eloquent you can get one row using first() method, it returns first row of table if where() condition is not found otherwise it gives the first matched row of given criteria.
It just returns null.
DB::raw() is used to make arbitrary SQL commands which aren't parsed any further by the query builder. They therefore can create a vector for attack via SQL injection.
The fact is that DB:select() returns an array, so you have to:
DB::select(DB::raw('select * from users'))[0];
You also can
DB::table('users')->first();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With