1. Go to this page and download the library: Download dcat/laravel-wherehasin library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dcat / laravel-wherehasin example snippets
/**
* SQL:
*
* select * from `test_users` where exists
* (
* select * from `test_user_profiles`
* where `test_users`.`id` = `test_user_profiles`.`user_id`
* )
* limit 10
*/
$users1 = User::whereHas('profile')->limit(10)->get();
/**
* SQL:
*
* select * from `test_users` where `test_users`.`id` in
* (
* select `test_user_profiles`.`user_id` from `test_user_profiles`
* where `test_users`.`id` = `test_user_profiles`.`user_id`
* )
* limit 10
*/
$users1 = User::whereHasIn('profile')->limit(10)->get();
User::whereHasIn('profile')->get();
User::whereHasIn('profile', function ($q) {
$q->where('id', '>', 10);
})->get();