Laravel 7/6 Elouqent firstWhere() Example
Hi Guys,
In this example,I will leran you how to use firstwhere in laravel 7/6 .you can simply and easy to use the firstwhere in laravel 7/6 .
The firstWhere method returns the first record for the table into the database.i will use email like [email protected] where equal get records into the database as bellow example.
Syntax :
firstWhere('colume name','value');
Example :
If we use firstWhere() then we can ignore one where condition. You can see my bellow where condition and first record and also you can see using firstWhere().
$user = User::where('email', '[email protected]')->first();
dd($user);
I am sure firstWhere will help you more. But If you have laravel 6 then and then you can use.
Let's see bellow example:
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
$users = User::firstWhere('email', '[email protected]');
dd($users);
}
Output :
array:9 [?
"id" => 1
"name" => "keval"
"email" => "[email protected]"
"email_verified_at" => null
"password" => "123456"
"active" => 0
"remember_token" => null
"created_at" => null
]
It will help you....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial