mercredi 21 août 2019

How can I create Resource Edit Form to fill multiple related records at one time in Laravel Nova admin?

I want to create the form, where I can fill multiple Relation records at one time.

I have created SeoMeta model with fields:

id  int(10) unsigned Автоматическое приращение   
seometable_type  varchar(255)   
seometable_id  int(10) unsigned   
key  text   
value  text   
lang  text   
created_at  timestamp NULL   
updated_at  timestamp NULL

My Model have Relation

public function seometas( string $lang = null )
    {
        $relation = $this->morphMany('App\Models\SeoMeta', 'seometable');

        if( isset($lang) && strlen($lang) ){
            $relation->where('lang', '=', $lang);
        }

        return $relation;
    }

In Nova resource I have the Panel in my Model that has many seo meta tags

new Panel('Seo Meta Data', [
                MorphMany::make('Seometas')
            ]),

And fields in SeoMeta

public function fields(Request $request)
    {
        $langVariants = config('app.allow_languages');
        $metasVariants = config('seo.allow_metas');

        return [
            ID::make()->sortable(),

            MorphTo::make('Model', 'seometable')->types([
                Model::class,
            ])->searchable(),


            Text::make('Locale', 'lang')
                ->sortable()
                ->rules('required', 'max:255')
                ->exceptOnForms(),

            Select::make('Locale', 'lang')->options($langVariants)
                ->onlyOnForms(),

            Select::make('Key', 'key')->options($metasVariants),

            Textarea::make('Value', 'value'),
            Text::make('Value', 'value')
                ->exceptOnForms(),

        ];
    }

When I try to Create new SeoMeta, I can fill the fields of each record in this way: default form But what I need is to fill all of allowed metatags in one particular form for one language like this

-form for Model#1 in English-
Title: [Field]
H1-header: [Field]
Description: [Field]
Keywords: [Field]
-/form-



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/30n3r81
via IFTTT

Aucun commentaire:

Enregistrer un commentaire