PHP code example of joonas1234 / nova-nested-form

1. Go to this page and download the library: Download joonas1234/nova-nested-form library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

joonas1234 / nova-nested-form example snippets


NestedForm::make($name, $viaRelationship = null, $class = null),

NestedForm::make('Posts'),

NestedForm::make('Posts', 'posts', Post::class),

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 Joonas1234\NestedForm\NestedForm;

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

            Gravatar::make(),

            Text::make('Name')
                ->sortable()
                ->rules('ke('Posts'),
        ];
    }

NestedForm::make('Posts')
->beforeFill(function ($request, $model, $attribute, $requestAttribute) {
    $request->merge(['key' => 'value']);
    // or
    if (!$model->hasSomeProperty) {
        throw new \Exception('You cannot do this.');
    }
})
->afterFill(function ($request, $model, $attribute, $requestAttribute, $touched) {
    $touched->each(function ($model) {
        if ($model->wasRecentlyCreated) {
            // do something
        }
    });
})

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

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

NestedForm::make('Posts')->open('only first'),

NestedForm::make('Posts')->heading('{{index}} // Post - {{title}}'),

NestedForm::make('Posts')->separator('\'),