Laravel 6 Elouqent firstWhere() Example

Laravel 6




Hi Guys,

In this example,I will leran you how to use firstwhere in laravel can simply and easy to use the firstwhere in laravel 6.

The firstWhere method returns the first record for the table into the database.i will use email like 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', '')->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', '');



Output :

array:9 [▼

"id" => 1

"name" => "keval"

"email" => ""

"email_verified_at" => null

"password" => "123456"

"active" => 0

"remember_token" => null

"created_at" => null


It will help you....

Recommended Posts