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.
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();
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]');
"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....