PHP code example of lupennat / nested-form

1. Go to this page and download the library: Download lupennat/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/ */

    

lupennat / nested-form example snippets


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

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

            Gravatar::make(),

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

NestedForm::make('Posts', Post::class)
    ->dependsOn('name', function(NestedForm $field, NovaRequest $novaRequest, FormData $formData) {
        if ($formData->name === 'xxx') {
            $field->min(1)->max(10);
        }
    })

NestedForm::make('Posts', Post::class)->dependsOn('name')

use Lupennat\Nova\Resource;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Lupennat\NestedForm\HasNestedForm;

class Posts extends Resource
{

    use HasNestedForm;

    public function fields(Request $request)
    {
        return array_filter([
            ID::make(),
            BelongsTo::make(__('User'), 'user', User::class),
            Select::section(__('Section'), 'section')->options(['sport' => 'Sport', 'news' => 'News'])->rules('

NestedForm::make('Posts', Post::class)
    ->prefill([
        ['title' => 'first post', 'section' => 'sport'],
        ['title' => 'second post', 'section' => 'news'],
    ])

NestedForm::make('Posts', Post::class)
    ->prefill([
        ['title' => 'first post', 'section' => 'sport'],
        ['title' => 'second post', 'section' => 'news'],
    ], true)

NestedForm::make('Posts', Post::class)
    ->heading(['section', 'title'], true)
    ->separator(' - ')