Skip to content

Instantly share code, notes, and snippets.

@DengoPHP
Last active September 8, 2021 06:51
Show Gist options
  • Select an option

  • Save DengoPHP/d3e95441a7b9e27299b7 to your computer and use it in GitHub Desktop.

Select an option

Save DengoPHP/d3e95441a7b9e27299b7 to your computer and use it in GitHub Desktop.
Laravel Eloquent with Subselect and Advanced Where
<?php
DB::table('rooms')
->whereNotIn('room_id', function($query)
{
$query->select('room_id')
->from(with(new Booking)->getTable())
->where(function($query)
{
$query->where('time_out', '<', '2012-09-14T18:00')
->orWhere('time_in', '>', '2012-09-21T09:00');
});
})
->orderBy('room_id')
->get();
@DengoPHP

Copy link
Copy Markdown
Author

You can leave this in your route.php to see the Query

Event::listen('illuminate.query', function()
{
echo '<pre>';
var_dump(func_get_args());
echo '</pre>';
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment