'Laravel Backpack

I need help. I am currently working with Laravel backpack and I have the following problem: I have a field called Media, that field has two behaviors, one to upload images and the other to write a URL, the problem is that it only lets me create the one time the field. Is there a way in laravel backpack to create 2 different fields with the same name?

I want to achieve something more or less like this:

CRUD::addField([ 'name' => 'url_media', 'label' => 'url_media', 'type' => 'upload', ]);

CRUD::addField([ 'name' => 'url_media', 'label' => 'url_media', 'type' => 'url', ]);



Solution 1:[1]

Because of the HTML spec, you cannot have two inputs with the same name in a form. I mean... you can. But only the last one will be sent in the request.

If you don't want to show both fields at the same time, you can use a conditional (if/else) to show either the upload field or the url field.

Otherwise, a different way would be to choose a fake name for the second field (say... url_media_link), then use a Laravel Mutator in your model, in this case setUrlMediaLinkAttribute() to do what you manipulate the model attributes as you want.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tabacitu