Home > OS >  Laravel how to validate two request inputs againt single column in form request
Laravel how to validate two request inputs againt single column in form request

Time:08-24

I am working with laravel 9.1. I want to validate two request inputs in single column of a table. below is my validation rule in form request.

Basically name = resource_name . permission_type i thought of merging both column before the validation but the problem is both fields needs to be validated first before concatination.

Can anyone please help me how do i validate resource_name and permission_type first and then check for resource_name.permission_type in the name column permission_types table.

Thankyou.

$name = $this->request->input('resource_name') . '.' . $this->request->input('permission_type');
$this->request->merge([
    'name' => $name,
]);

return [
    'type' => ['required'],
    'resource_name' => ['required', 'alpha', 'min:3', 'max:50'],
    'permission_type' => ['required'],
    'name' => ''
];

CodePudding user response:

Try this

    $name = $request->validate([
        'type' => ['required'],
        'resource_name' => ['required'],
        'permission_type' => ['required'],
        'name' => [
            $request->input('resource_name'). '.' .$request->input('permission_type')
        ]
    ]);

CodePudding user response:

Add this code :

     $validatedData = $request->validate([


     'resource_name' => ['required', 'alpha','min:3', 'max:255'],



     'permission_type' => ['required'],
     ]);
  • Related