Download the PHP package lupennat/nova-nested-many without Composer
On this page you can find all versions of the php package lupennat/nova-nested-many. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nova-nested-many
- Requirements
- Installation
- Usage
- HasNestedMany Field
- DependsOn
- Propagate
- Default Children
- Additional options
- Hooks
- Nestable Resource
- Nestable Title
- Nestable Custom Validation
- Nestable Authorization
- Nestable Actions
- Nestable Basic Actions
- Nestable Soft Delete Action
- Nestable Custom Actions
- Difference With Nova Actions
- Nested Object
- Recursivity
- Changelog
- Credits
Requirements
php: ^7.4 | ^8
laravel/nova: ^4
Installation
NOVA | PACKAGE |
---|---|
<4.29.5 | 1.x |
>4.29.6 | 2.x |
Usage
Register Trait HasNestedResource
globally on Resources.
Use HasManyNested
Field like HasMany
HasManyNested is visible by deafult on DetailPage, UpdatePage and CreatePage. HasManyNested is not available on IndexPage.
Implements contract Nestable
and use trait HasNested
for every related model that will be used with HasNestedMany
.
HasNestedMany Field
Depends On
HasNestedMany
Field support Nova dependsOn
.
Propagate
HasNestedMany
Field can propagate parent field value to related resource.
On related resource propagated fields can be retrieved through getNestedPropagated
method on Request
Default Children
You can use defaultChildren
method to generate a default set of related resource when children are empty.
defaultChildren works only on Create Page.
if you want to overwrite existing children you can use
Additional options
function | description | default |
---|---|---|
->collapsedChildrenByDefault() |
Collapse Children on Panel View | false |
->useTabs(bool = true) |
switch display mode to tabs instead of panels | false |
->active(int = 0) |
set default active item by index | 0 |
->activeTitle(string) |
set default active item by title | null |
->canChangeViewType(bool = true) |
enable switch view type button | false |
->hideFields(array<string>) |
Hide fields on related resource | [] |
->lock(bool = true) |
Disable Add/Remove buttons for related resource | false |
->min(int = null) |
Set Min children | null |
->max(int = null) |
Set Max children | null |
Hooks
You can specify callbacks before and after HasNestedMany
fill the database.
Nestable Resource
Resource trait HasNestedResource
, provide new functionality related to Nested.
Nestable Title
Both panel and tab views, use nestedTitle
method to retrieve the title of the resource.
if method not found it will fallback to original nova resource title
Nestable Custom Validation
Field validation on nestable resources are automatically managed by NestedMany
, for each validation error the attribute key is reprocessed and mapped to show feedback to the user in the specific field of the resource generating the error.
When validation is done by adding errors in the validator (e.g., using the afterValidation method), HasManyNested is unable to intercept and remap these errors.
On related resource the correct prefix to prepend to the error attribute can be retrieved through getNestedValidationKeyPrefix
method on Request.
Nestable Authorization
Nested Many will use laravel nova resource authorizations for create/update/delete. You can define different policies only for Nested Many within 3 new methods
Nestable Actions
You can define Nested Actions to manipulate related content through the server.\
Nested
Actions can keep the modal open after action is run through the property$keepOpened
or the methodkeepOpened()
.
Nestable Basic actions
By Default NestedMany has 3 Basic actions NestedBasicAddAction
, NestedBasicDeleteAction
, NestedBasicRestoreAction
, and it is possible to customize them through 3 methods on resource.
Nestable Soft Delete Action
NestedDeleteAction automatically support softDelete
logic (is not a real elouquent softDelete), to enable softdelete/restore logic you need to set protected $nestedHasSoftDelete = true
on the related model.
Nestable Custom actions
Nested actions may be generated using the nested-many:action Artisan command. By default, all actions are placed in the app/Nova/NestedActions directory:
You may generate a destructive action by passing the --destructive option:
Nested Actions have a lot in common with Nova Actions, the main difference is that handle
method should always return a collection of NestedObject
.
You can generate new NestedObject
with method $this->getNewNested()
.
To learn how to define Nova actions, let's look at an example. In this example, we'll define an action that will duplicate a post:
You can register custom NestedActions
within your resource throught the method nestedActions
Nested Object
When using NestedActions
, all Eloquent
models are wrapped by default in the Nested
class that extends Laravel Fluent
class.\
All Model attributes are replicated on Nested
attributes, that way you can modify attributes values directly to the Nested
object.
It expose convinient methods to manipulate object without executing queries against the database.
function | description | return |
---|---|---|
->delete() |
Delete/SoftDelete item | self |
->restore() |
Restore item | self |
->active(bool = true) |
Set item as active | self |
->isStored() |
Detected if item is stored on database | bool |
->isDeleted() |
Detect if item is SoftDeleted | bool |
->hasSoftDelete() |
Detect if item support SoftDelete | bool |
->getKeyName() |
Get Eloquent Original keyName | string |
->toModel() |
Convert current item to Original Eloquent Model | Model |
When toModel is called, Nested class apply changes on current object to Original Eloquent Model if Mutators are registered, they will be executed.
Every change executed on Nested Object will not be stored on database until the user click the Create/Update button on the Parent Form Page.
Recursivity
HasManyNested
supports recursivity however, it is important to keep in mind that the deletion of a "parent" resource is not recursive to its "children".
Ex. parent resource -> nested resourceA -> nested resourceB
by deleting a nested resource A the nested resources B are not automatically deleted from the database.
You can solve this problem by directly using observers for the delete event on eloquent models.
Nestable Objects with Recursivity
Recursive HasManyNested
relations, are available within the children collection of NestedActions
, relations are array of Nested Object
.
You can generate new relation NestedObject
with method $this->getNewNested('relationName')
.
Credits
NestedForm field is based on original Nova Nested Form.