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.