Laravel validation required_without for media file

Viewed 283

I'm using media library for file field. I have a two fields custom_url and media field in my form which either custom_url OR media need to be filled.

I'm validating the form using laravel request validation and the required_without rule, which looks like this.

I'm using nova package.

Text::make(__('Custom Url'), 'custom_url')
                ->rules('required_without:file')
                ->help('Required without file upload'),

Files::make('File', 'file')
                ->rules('required_without:custom_url')
                ->help('Required without Custom URL'),

I am uploading file but although it's showing me error always Custom URL is required.

I think file field is returning null value. Can anyone please guide me that how may I do it?

2 Answers

Please check your migration table and also store method. Then look at the form field name and migration column name is as same or not.

It is probably you are missing enctype="multipart/form-data" in your form declaration.

So it has to be <form method="..." action="..." enctype="multipart/form-data">

Related