Как устроены массивы в PHP и как код влияет на скорость работы с ними
https://habr.com/ru/articles/947162/
https://habr.com/ru/articles/947162/
- ❤️44
Product::query()
- ->with([
- 'attribute' => fn (Builder $query) => $query->select(['id', 'title'])
- ])
- ->whereHas('attribute');
+ ->withWhereHas('attribute:id,title') Product::query()
- ->whereHas('attribute', fn (Builder $query) => $query
- ->where('id', $id)
- );
+ ->whereRelation('attribute', 'id', $id) Product::query()
- ->with([
- 'attribute' => fn (Builder $query) => $query->select(['id', 'title'])
- ])
- ->whereHas('attribute', fn (Builder $query) => $query
- ->where('id', $id)
- );
+ ->with('attribute:id,title')
+ ->whereRelation('attribute', 'id', $id)