The database query builder in Laravel provides a simple, intuitive interface for generating and performing database queries. It works with every one of Laravel's supported database systems and may be used to conduct most operations on the database in your application.

Today, in this post, I'll show you an example of a laravel query builder where exists. When using the where exists clause in sql in Laravel. And we can utilize sql where exists clause in our laravel project thanks to whereExists.

As a result, it is incredibly simple to use and learn. In the where condition, we can use the SELECT query.

We can learn how to utilize whereExists in our application by looking at the example below.

1. SQL Query

SELECT *
FROM `items`
WHERE EXISTS
    (SELECT `items_city`.`id`
     FROM `items_city`
     WHERE items_city.item_id = items.id)

2. Using Laravel Query Builder

DB::table('items')
    ->whereExists(function ($query) {
        $query->select("items_city.id")
              ->from('items_city')
              ->whereRaw('items_city.item_id = items.id');
    })
    ->get();

I hope you will like the content and it will help you to learn Laravel Query Builder Where Exists Example
If you like this content, do share.


Recommended Posts

View All

How to Create a Barcode in a Laravel 9 Application


Laravel 9 barcode generator tutorial; This step-by-step tutorial will show you how to create a barcode in your Laravel app from scratch using the milo...

Laravel whereMonth and whereYear Example


laravel whereMonth and whereYear example, whereMonth, whereYear, where condition in laravel 8, date function in laravel 8, whereMonth and whereYear in...

Laravel 9 Ajax Form Validation Example


In Laravel 9, we may ajax submit a form following validation. Laravel's ajax form validation is simple.

Laravel 9 FullCalendar Ajax Tutorial with Example


We'll show you how to use the Fullcalendar JavaScript event calendar plugin to add FullCalendar to your Laravel app and create and cancel eve...

Laravel Where Clause with MySQL Function Example


laravel eloquent where year,laravel eloquent mysql functions,laravel eloquent where clause mysql,mysql function mysql laravel