Home > Enterprise >  How to validate data (coming in request) from another (buyers) table using laravel 8
How to validate data (coming in request) from another (buyers) table using laravel 8

Time:12-21

I have 2 different tables based on their types: User & Buyer. I am validating "buyers" data but it checks in the "users" table rather than in the "buyers" table, Is there any way to ask Validator Facade to check in the "buyers" table.

$validator = Validator::make($request->all(), [
                    'name' => 'required',
                    'user_type' => 'required',
                    'phone' => 'required|unique:users|max:11|min:11',
                    'email' => 'required|email|unique:users',
                    'password' => 'required|min:8',
                    'passowrd_confirmation' => 'required|same:password',
                ]);

CodePudding user response:

https://laravel.com/docs/8.x/validation#specifying-a-custom-column-name

According to the documentation, you can indicate a specific field of any of your tables for validation. In this way you can do:

'name' => 'required:buyers, name'
  • Related