Laravel Elouqent firstWhere() Example

Today now in this example,I will show you how we can use firstwhere in laravel application . we can simply and also easy to use the firstwhere in laravel application .

The firstWhere method is returns the first record for the table from the database. So here i will use email like and where equal get records from the database as bellow example.

Syntax :

firstWhere('colume name','value');

Example :

So if we want to use firstWhere() then we can ignore one where condition. Now here we can see on the bellow where condition and first record and also we can see by using firstWhere().

$user = User::where('email', '')->first();


Here I am sure that the firstWhere will help us more. But If we have laravel 6 then and then we 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

Read Also : Laravel 8 Eloquent Global Scope Tutorial Example

I hope it will help you. Also you can follow us on Facebook


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →