Laravel Eloquent firstWhere() Example

In this example i explain Laravel eloquent firstWhere() example. We simple way to use laravel eloquent function in application. Also i explain how to use laravel firstWhere() eloquent in laravel application.

In this example to you can use easily firstWhere eloquent with laravel 6, laravel 7 and laravel 8. Laravel firstWhere() eloquent is use to get first record of your where condition.

Read Also :  Laravel 8 Resource Route Controller Example

Laravel eloquent firstWhere() is same work as first() method in laravel application. Also Laravel firstWhere() and first() method same work as find() method, but firstWhere() and first() method use for name, slug and string column. Laravel firstWhere() eloquent to easily get match first record into your database.

Laravel Eloquent firstWhere() Example

namespace App\Http\Controllers;
use App\Models\Category;
class CategoryController extends Controller

    public function index()
         	We can ignore to write this query.
         	$category = Category::where("name", "Laptop")->first(); 
        $category = Category::firstWhere("name", "Laptop");

I hope you understand laravel firstWhere….