Hello Devs,
In this tutorial, we will learn Laravel 7/6 Elouqent firstWhere() Example
The firstWhere method returns the first record for the table into the database. We will use email like abc@gmail.com where equal get records into the database as bellow example.
Follow this step by step guide below.
Syntax :
firstWhere('colume name','value');
Example :
$user = User::where('email', 'kevalkashiyani9@gmail.com')->first();
dd($user);
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
]
May this example help you.