Laravel 8 Eloquent withExists() Example

May 19, 2021 . Admin

Hi Dev,

Today, I will learn you how to use laravel 8 exists query builder. i explained simply about laravel exists() example. you will learn how to check if record exists in laravel. i explained simply about laravel check if record exists in database.

You can check if records is exists or not in database in your laravel 6, laravel 7 and laravel 8 projects.

Laravel added eloquent methods exists() for check if record exists in database table or not. so i will give you very simple example so you don't need to use first() and then check is null or not. we will use direct exists() that will help you to determine if exist or not.

exists() methods return true or false value so you have to just put in your condition.

Here, I will show full example of exists() methods follow my step.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Product;
use Illuminate\Support\Facades\DB;

class ProductController extends Controller
     * Write code on Method
     * @return response()
    public function index()
      $is_exists = Product::select("*")->where("name","dell")->exists();

        dd("Records is Available");
        dd("Records is not Available");


"Records is Available"

I Hope It will help you..

#Laravel 8 #Laravel