Skip to content

Commit

Permalink
Add performance tips to README.md (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwilby authored May 7, 2021
1 parent d90ee0e commit 4190df3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,43 @@ If you do use nova-translatable and would like to return the translated name add
}
```

## Performance Tips

When attaching this field to a resource, you may include the field relation in the `$with` property for that resource to prevent n+1 issues when loading an index page for that resource.
```php
class Company extends Resource
{
public static $with = [];
}

class Department extends Resource
{
public static $with = ['company'];
}

class Location extends Resource
{
public static $with = ['department', 'company'];
}
```

You may also choose to cache your top-level model to reduce the number of queries made to the database for each row in an index.
```php
NovaBelongsToDepend::make('Company')
->options(Cache::remember(
'companies',
60,
function () {
return Company::all();
}
)),
NovaBelongsToDepend::make('Department')
->dependsOn('Company')
->optionsResolve(function($company) {
return $company->departments;
})
```

## Sample

[Demo Project](https://github.com/orlyapps/laravel-nova-demo)
Expand Down

0 comments on commit 4190df3

Please sign in to comment.