File name field required when the file uploads laravel validation rule,using required_with laravel validation rule make file name field required when the user upload file else the file and file name both field will be nullable, in this post you will validate how to make the file name field required when the file field is filled using laravel validation rules, This is a very simple quick validation rule method required_with
The below laravel example will help you to make the required file name filed when the user enters a file or document, generally document field is optional when a user enters their data, but when a user likes to upload the document that time they need to specify which document they entered in the form so the verification team understands that document type very well.
So when the user does not like to upload a document not mandatory document name field, but when a user likes to upload a document file that time is necessary to take its file type name that time it will require a field using laravel validation rules.
Here is a simple example given how to make the required file name when a file or document is uploaded by the user using laravel validation rules.
public function store(Request $request) { $validator = $request->validate([ 'doc_1' => 'nullable|mimes:doc,txt,git,png,jpg,jpeg,pdf|max:2048', 'doc_1_text' => 'nullable|required_with:doc_1,empty|max:100', ],[ 'doc_1_text.required' => 'The doc 1 name field is required.', 'doc_1_text.required_with' => 'The doc 1 name field is required when doc 1 available.', ]); }
We always thanks to you for reading our blogs.

Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- How To Generate Digital Invoice PDF In Laravel Demo
- Different Solutions For Fix 419 Page Expired laravel
- Sendgrid Email Send Tutorial Laravel/PHP/cURL Example
- Laravel 9 REST API with Passport Authentication Tutorial
- average() Method | Laravel Collection Example
- How To Exchange Currency Rates In Laravel Example
- resize image and upload example laravel intervention
- Microsoft Authentication Implement on Laravel App
- Where Clause In Laravel Eloquent Example
- How to Upload Multiple Images In Laravel 10