Skip to content

Instantly share code, notes, and snippets.

@ryanmr
Last active February 4, 2016 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmr/31de16c813072a8f08a4 to your computer and use it in GitHub Desktop.
Save ryanmr/31de16c813072a8f08a4 to your computer and use it in GitHub Desktop.
$episodes = App\Episode::with(['related'])
->visible()
->recent()
->withSlug('pk')
->orWhere(function($query){
$query->withSlug('tf')->
whereHas('related', function($query){
$query->where('type', '=', 'parent')
->whereHas('related.series', function($query){
$query->where('slug', '=', 'pk');
});
});
})
->get();
array:1 [▼
0 => array:3 [▼
"query" => "select * from `episodes` where `hidden` = ? and `unlisted` = ? and `state` = ? and exists (select * from `series` where `episodes`.`series_id` = `series`.`id` and `slug` = ?) and (exists (select * from `series` where `episodes`.`series_id` = `series`.`id` and `slug` = ?) and exists (select * from `episodes_relations` as `self_9e8d1f05b12ae4be32b4eba78bbc6315` where `self_9e8d1f05b12ae4be32b4eba78bbc6315`.`episode_id` = `episodes`.`id` and `type` = ? and exists (select * from `episodes` inner join `episodes_relations` on `episodes`.`id` = `episodes_relations`.`episode_related_id` where `episodes_relations`.`episode_id` = `episodes`.`id` and exists (select * from `series` where `episodes`.`series_id` = `series`.`id` and `slug` = ?) and `episodes`.`deleted_at` is null) and `episodes`.`deleted_at` is null)) and `episodes`.`deleted_at` is null order by `published_at` desc, `created_at` desc"
"bindings" => array:7 [▼
0 => false
1 => false
2 => "published"
3 => "pk"
4 => "tf"
5 => "parent"
6 => "pk"
]
"time" => 7.32
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment