rapyd-laravel icon indicating copy to clipboard operation
rapyd-laravel copied to clipboard

Form validation unique more than 1 fields

Open CHOMNANP opened this issue 9 years ago • 4 comments

I'm trying to get my form validation more than 1 fields. Is it possible?

$form = \DataForm::source(new ProjectAssignment()); $form->add('project_id', 'P ID' , 'select')->options(Project::All()->pluck('code', 'id'))->rule('required); $form->add('employee_id', 'E ID' , 'select')->options(Employee::All()->pluck('name', 'id'))->rule('required');

Anyone experience with this?

CHOMNANP avatar Sep 19 '16 08:09 CHOMNANP

Yes it is, what's the issue?

tacone avatar Sep 21 '16 14:09 tacone

For example, I have a table with unique fields('project_id','employee_id'). So far, I found there is an option to use "$form->add('project_id', 'P ID' , 'select')->options(Project::All()->pluck('code', 'id'))->rule('required|unique);", but this only check for 1 field. Is there a way to check 2 unique fields.

Something like rule('required|unique:myTable,project_id|uniqueWith:myTable,employee_id'); Thanks.

CHOMNANP avatar Sep 23 '16 03:09 CHOMNANP

rapyd uses the laravel native validator. i suggest you to check the laravel docs to see if it's possible or note. If not, you can still create a custom validation (again, check the laravel docs to learn how to), and use it with rapyd.

tacone avatar Sep 27 '16 08:09 tacone

There are some Custom Validater available. I'll try and see. I'll update the ticket once I find the solution :)

Thank Tacone.

CHOMNANP avatar Sep 30 '16 11:09 CHOMNANP