Laravel 7/6 Elouqent firstWhere() Example

10-Apr-2023

.

Admin

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 abc@gmail.com 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', 'kevalkashiyani9@gmail.com')->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', 'kevalkashiyani9@gmail.com');

dd($users);

}

Output :

array:9 [?

"id" => 1

"name" => "keval"

"email" => "kevalkashiyani9@gmail.com"

"email_verified_at" => null

"password" => "123456"

"active" => 0

"remember_token" => null

"created_at" => null

]

It will help you....

#Laravel 7

#Laravel

#Laravel 6