Answer the question
In order to leave comments, you need to log in
Why doesn't eager load fetch condition work in Laravel?
Hello everyone, I'm trying to make a selection with a connected model
ProductCategory::with(['domains' => function ($query) {
$query->where('title', 'like', '%czechpartyking.de%');
}])->toSql();
"select * from `product_categories` where `product_categories`.`deleted_at` is null"
select `domains`.*, `domain_category_pivot`.`category_id` as `pivot_category_id`, `domain_category_pivot`.`domain_id` as `pivot_domain_id` from `domains` inner join `domain_category_pivot` on `domains`.`id` = `domain_category_pivot`.`domain_id` where `domain_category_pivot`.`category_id` in (5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28) and `ame` = czechpartyking.de
Answer the question
In order to leave comments, you need to log in
Returns extra, even those records that have no connection
The with method generates a separate query that will be executed after receiving the results of the main one, so toSql does not return it either. Install Debugbar or Telescope and see requests there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question