Laravel Eloquent firstOr() Example

This post provide example of firstOr() function in Laravel. In this example i explain Laravel Eloquent firstOr() Example. The example of laravel firstor example then you are a right place. we will help you to give example of firstor in laravel.

Also i will give you very easy example of how to use firstOr() with laravel eloquent. you can simply use firstOr() with laravel 6, laravel 7 and laravel 8 version.

Read Also :  How to Allow only 10 Numbers in Textbox using jQuery

Laravel Eloquent firstOr() Example

<?php
  
namespace App\Http\Controllers;
  
use App\Models\Product;
  
class SignaturePadController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {

  
        $product = Product::where("name", "Apple")->firstOr(function () {
            return Product::where("name", "Samsung")->first();
        });  
  
        dd($product);
    }
}

I hope you understand laravel firstOr() example…