How to access attributes of a selected record, without duplicate queries?
Hi, I want to display additional information of the selected company using Placeholders. But each time I use
Company::find($get('company_id'))
an additonal query will be fired. How can I prevent this?
In the example above, 2 duplicate queries are created.
Thank you!Solution:Jump to solution
->content(fn (Get $get) => static::getCompany($get('id'))
```php
static function getCompany(int|string $id) {
return once(fn () => Company::find($get('company_id'))?->fullAddress));...4 Replies
You can't access the record directly. I usually add a function to cache the response for a short period.
do you have an example?
Solution
->content(fn (Get $get) => static::getCompany($get('id'))
oh, cool "hack". Worked perfectly.