All Projects → yassipad → Laravel Nova Nested Form

yassipad / Laravel Nova Nested Form

This package allows you to include your nested relationships' forms into a parent form.

Projects that are alternatives of or similar to Laravel Nova Nested Form

Nova Custom Email Sender
A Laravel Nova tool that sends ad-hoc email messages from the dashboard.
Stars: ✭ 62 (-63.31%)
Mutual labels:  laravel, nova, tool
Nova Backup Tool
A Laravel Nova tool to backup your app
Stars: ✭ 260 (+53.85%)
Mutual labels:  laravel, nova, tool
Nova Tail Tool
A Laravel Nova tool to display the application log
Stars: ✭ 110 (-34.91%)
Mutual labels:  laravel, nova, tool
Nova Advanced Image Field
🌄📐 A Laravel Nova advanced image field with cropping and resizing using Cropper.js and Intervention Image
Stars: ✭ 67 (-60.36%)
Mutual labels:  laravel, nova
Laravel Nova Permission
A Laravel Nova tool for the Spatie Permission package
Stars: ✭ 59 (-65.09%)
Mutual labels:  laravel, nova
Laravel Cadillac
🍺 A database tool for laravel.
Stars: ✭ 63 (-62.72%)
Mutual labels:  laravel, tool
Nova Laravel Update Card
Check if you're running the latest Laravel version right from your Nova dashboard.
Stars: ✭ 34 (-79.88%)
Mutual labels:  laravel, nova
Collapsible Resource Manager
A custom sidebar menu with collapsible groups
Stars: ✭ 100 (-40.83%)
Mutual labels:  laravel, nova
Nova Stripe Theme
A Laravel Nova theme closely resembling Stripe.
Stars: ✭ 71 (-57.99%)
Mutual labels:  laravel, nova
Nova Indicator Field
A colour-coded indicator field for Laravel Nova
Stars: ✭ 108 (-36.09%)
Mutual labels:  laravel, nova
Nova Repeatable Fields
A Laravel Nova field for configuring repeatable sets of fields
Stars: ✭ 126 (-25.44%)
Mutual labels:  laravel, nova
Nova Route Viewer
Route viewer tool for Laravel Nova
Stars: ✭ 54 (-68.05%)
Mutual labels:  laravel, nova
Nova Mega Filter
Allows you to control the columns and filters shown on any Nova resource index
Stars: ✭ 49 (-71.01%)
Mutual labels:  laravel, nova
Nova Time Field
Laravel Nova Time Field
Stars: ✭ 45 (-73.37%)
Mutual labels:  laravel, nova
Nova Translatable
Making Nova fields translatable
Stars: ✭ 119 (-29.59%)
Mutual labels:  laravel, nova
Nova Settings Tool
Laravel Nova tool to view and edit application settings.
Stars: ✭ 131 (-22.49%)
Mutual labels:  laravel, nova
Awesome Nova
🎉 A curated list of awesome things related to Laravel Nova
Stars: ✭ 92 (-45.56%)
Mutual labels:  laravel, nova
Laravel Web Tinker
Tinker in your browser
Stars: ✭ 664 (+292.9%)
Mutual labels:  laravel, tool
Laravel Honeypot
Preventing spam submitted through forms
Stars: ✭ 728 (+330.77%)
Mutual labels:  laravel, form
Nova Cashier Manager
Managing Stripe subscriptions inside the incredible Laravel Nova admin panel.
Stars: ✭ 150 (-11.24%)
Mutual labels:  laravel, nova

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads

Nova Nested Form

This package allows you to include your nested relationships' forms into a parent form.

Installation

composer require yassi/nova-nested-form

Contributions

As I did not anticipate so many people would use that package (which is awesome) and simply do not have enough time to update/enhance this package more regularly on my own, I am looking for other contributors to help me with the maintenance and feature requests. Don't hesitate to contact me if you're interested!

Update to 3.0

The afterFill and beforeFill methods are no longer available.

Attach a new relationship form to a resource

Simply add a NestedForm into your fields. The first parameter must be an existing NovaResource class and the second parameter (optional) must be an existing HasOneOrMany relationship in your model.

namespace App\Nova;

use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Gravatar;
use Laravel\Nova\Fields\Password;
// Add use statement here.
use Yassi\NestedForm\NestedForm;

class User extends Resource
{
    ...
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            Gravatar::make(),

            Text::make('Name')
                ->sortable()
                ->rules('required', 'max:255'),

            Text::make('Email')
                ->sortable()
                ->rules('required', 'email', 'max:254')
                ->creationRules('unique:users,email')
                ->updateRules('unique:users,email,{{resourceId}}'),

            Password::make('Password')
                ->onlyOnForms()
                ->creationRules('required', 'string', 'min:6')
                ->updateRules('nullable', 'string', 'min:6'),

            // Add NestedForm here.
            NestedForm::make('Posts'),
        ];
    }

Choose when to display the form

For instance, if the nested form should only be available if the value of the "has_comments" attirbute is true, you can use:

class Post extends Resource
{
    ...
    public function fields(Request $request)
    {
        return [
            Boolean::make('Has Comments'),
            NestedForm::make('Comments')->displayIf(function ($nestedForm, $request) {
               return [
                    [ 'attribute' => 'has_comments', 'is' => true ]
               ];
        ];
    }
})

The displayIf method is excepted to return an array of array as you may want to add several conditions.

class Post extends Resource
{
    ...
    public function fields(Request $request)
    {
        return [
            Boolean::make('Has Comments'),
            Text::make('Title'),
            Text::make('Subtitle')->nullable(),
            Number::make('Number of comments allowed'),
            NestedForm::make('Comments')->displayIf(function ($nestedForm, $request) {
                return [
                    [ 'attribute' => 'has_comments', 'is' => true ],
                    [ 'attribute' => 'title', 'isNotNull' => true ],
                    [ 'attribute' => 'subtitle', 'isNull' => true ],
                    [ 'attribute' => 'title', 'includes' => 'My' ],
                    [ 'attribute' => 'number_of_comments_allowed', 'moreThanOrEqual' => 1 ],
                ];
            })
        ];
    }
}

The package will then add those conditions and dynamically update your form as you fill the fields. The available rules are:

  • [x] is
  • [x] isNot
  • [x] isNull
  • [x] isNotNull
  • [x] isMoreThan
  • [x] isMoreThanOrEqual
  • [x] isLessThan
  • [x] isLessThanOrEqual

Add a minimum or a maximum number of children

For instance, if you want every user to have at least 3 posts and at most 5 posts, simply use:

NestedForm::make('Posts')->min(3)->max(5),

Please note that the package automatically detects whether the relationship excepts many children or a single child, and sets the maximum value accordingly.

When creating a new user, 3 blank posts will be displayed. If you reach the maximum number of posts, the "Add a new post" button will disappear.

Set the default open/collapse behavior

If you want the nested forms to be opened by default, simply use:

NestedForm::make('Posts')->open(true),

Modify the default heading

You can modify the default heading using the heading() method. You can use the helper method wrapIndex() to add the current child index to your header.

NestedForm::make('Posts')->heading(NestedForm::wrapIndex() . ' // Post'),

You can also add any attribute of the current child into your heading using the helper method wrapAttribute().

NestedForm::make('Posts')->heading(NestedForm::wrapIndex() . ' // ' . NestedForm::wrapAttribute('title', 'My default title')),

Modify the index separator

You can modify the default index separator using the separator() method when you have nested forms (e.g. 1. Post, 1.1. Comment, 1.1.1. Like).

NestedForm::make('Posts')->separator('\'),
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].