tgoop.com/laravel_it/2716
Create:
Last Update:
Last Update:
Часто используемые способы взаимодействия с релейшенами Laravel и их улучшение
1) Первый
Product::query()
- ->with([
- 'attribute' => fn (Builder $query) => $query->select(['id', 'title'])
- ])
- ->whereHas('attribute');
+ ->withWhereHas('attribute:id,title')
2) Второй
Product::query()
- ->whereHas('attribute', fn (Builder $query) => $query
- ->where('id', $id)
- );
+ ->whereRelation('attribute', 'id', $id)
3) Третий
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)
BY Laravel World
Share with your friend now:
tgoop.com/laravel_it/2716