Laravel Query Builder Where Exists Example
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, we will show you an example of a laravel query builder where exists. When using the where exists clause in SQL Query 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 code below.
SQL Query:
SELECT *
FROM `items`
WHERE EXISTS
(SELECT `items_city`.`id`
FROM `items_city`
WHERE items_city.item_id = items.id)
Using Laravel Query Builder:
Item::query()
->whereExists(function ($query) {
$query->select("items_city.id")
->from('items_city')
->whereRaw('items_city.item_id = items.id');
})
->get();
I hope it can help you..
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Sum Query with Where Condition Example
- Laravel Group By with Min Value Query Example
- Laravel Group By with Max Value Query Example
- Laravel Case Sensitive Query Search Example
- PHP Laravel Left Join Query Example
- PHP Laravel Inner Join Query Example
- Laravel Eloquent whereNotNull() Query Example
- Laravel Eloquent whereNotBetween() Query Example
- Laravel Eloquent whereBetween() Query Example
- Laravel Eloquent Where Query Examples
- How to Create and Use Query Scope in Laravel Eloquent
- How to use Union Query with Laravel Eloquent?
- How to Get Query Strings Value in Laravel?