Laravel : Retrieve a single record from database

In this tutorial learn how to retrieve a single row/columns/record using database query, If you  want to retrieve a single row/record from the database table, you may use the first method. This method will return a single stdClass object.


and display record.

$singleRecord = DB::table('users')->where('name', 'Nakiya')->first();

echo $singleRecord->name;

If you don't even need an entire row, you may extract a single value from a record using the value method. This method will return the value of the column directly:


$add = DB::table('users')->where('name', 'Nakiya')->value('address');

echo $add->address;

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...