Download the PHP package lupennat/nova-better-lens without Composer
On this page you can find all versions of the php package lupennat/nova-better-lens. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nova-better-lens
- Requirements
- Installation
- Usage
- Trait Improvements
- Authorization
- Hide From Toolbar
- With Related
- Per Page
- Decorate Collection
- Resource Link Parameters
- Create Link Parameters
- Breadcrumbs
- Many Fields
- Lens Field
Requirements
php: ^7.4 | ^8
laravel/nova: ^4
Installation
NOVA | PACKAGE |
---|---|
<4.29.5 | 1.x |
>4.29.6 | 2.x |
Usage
Laravel Nova Better Lens, improve Nova Lenses Behaviours
Include trait on Lens.
Trait Improvements
Authorization
Better Lens provide the ability to define authorization for lens. You can override parent resource methods using standard laravel authorization methods.
Authorize To Create
By Default Nova Lens does not provide the ability to Create/Attach resource, to mantain compatibility authorizedToCreate
will work only if lens will be loaded with many* Fields or if the method is explicitly defined in the lens.
Hide From Toolbar
Better Lens provide the ability to exclude a lens from parent resource toolbar list by the static method hideFromToolbar
(by default is false).
With Related
Better Lens provide the ability to make lens Viewable only as related resource.\
By default all lens on Nova can be linked on Menu and can be loaded as a standalone index resource. With static method withRelated
, you can override default behaviour and prevent lens to be loaded without a viaResource
request (by default is empty array).
Per Page
Better Lens provide the ability to define perPage
options for lens. Using static methods perPageViaRelationship
and perPageOptions
you can override parent resource perPage
options (by default use parent resource options).
you can also choose to show pagination filter when lens are loaded as relation via static showPaginationViaRelationship
method (by default is false
).
Decorate Collection
Better Lens provide the ability to manipulate the collection of models returned by the query, you can override the static method decorateCollection
and change the collection before it will be used to serialization (by default it return the original collection).
Returned Collection should always return a Collection of Eloquent models, returning other types can generate runtime errors.
Resource Link Parameters
Better Lens provide the ability to define extra parameters for view and edit url. You can define a list of parameter => value
using static method resourceLinkParameters
(by Default is empty array).
Create Link Parameters
Better Lens provide the ability to define extra parameters for creation url. You can define a list of parameter => value
using static method createLinkParameters
(by Default is empty array).
Breadcrumbs
Better Lens provide the ability to override default Breadcrumbs for Lens pages using method breadcrumbs
(by Default Nova Lens page breadcrumbs are loaded).
Many Fields
Better Lens automatically enable a new method lens
for all Many Relationship Fields:
- BelongsToMany
- HasMany
- HasManyThrough
- MorphedByMany
- MorphMany
- MorphToMany
many relationship will load the lens view instead of the main resource.
Lens Field
Better Lens provide a new field Lens
that can be used to load a resource lens without a "real many relationship".\
By the field Lens
it is possible to create a related table without creating a Custom ResourceTool.
Example
We want to load a table with all translation key and the related translation value for current website.
The table translation_keys
does not have a real relation with the website resource and only contains all the translation keys. The table translations
instead contains both the relation with key and website.\
We don't want to use directly the translations
table because we will lost the key not translated for the current website, we need to start from translation_keys
table and load the website value from the translations
table if present.