Laravel Eloquent firstWhere() Example
This post will give you example of laravel firstWhere. i explained simply about laravel eloquent firstwhere example. you'll learn laravel firstwhere example. We will use firstwhere in laravel.
Here i will give you very simple example of how to use firstWhere() with laravel eloquent. you can easily use firstWhere() with laravel 6, laravel 7 and laravel 8 version.
When we need to get record from id then we can easily get from find() method, but when you need to get record from slug or name then you have to use first() method. But laravel eloquent provide firstWhere() method that will help you to easily get match first record.
Let's see example:
class SignaturePadController extends Controller
* Write code on Method
* @return response()
public function index()
We can ignore to write this query.
$category = Category::where("name", "Mobile")->first();
$category = Category::firstWhere("name", "Mobile");
I hope it can help you...
We are Recommending you
- Laravel Eloquent withSum() and withCount() Example
- Laravel Eloquent Group By Example
- Delete All Records from Table in Laravel Eloquent
- Laravel Eloquent inRandomOrder() Method Example
- Laravel Eloquent whereNotNull() Query Example
- Laravel Eloquent whereNotBetween() Query Example
- Laravel Eloquent selectRaw() Query Example
- Multiple orWhere Condition in Laravel Eloquent
- Laravel Eloquent Where Query Examples
- How to Create and Use Query Scope in Laravel Eloquent
- Laravel Has Many Through Eloquent Relationship Tutorial