zofe / rapyd-laravel

deprecated rewritten in rapyd-livewire
MIT License
866 stars 297 forks source link

Form validation unique more than 1 fields #360

Open CHOMNANP opened 8 years ago

CHOMNANP commented 8 years ago

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?

tacone commented 8 years ago

Yes it is, what's the issue?

CHOMNANP commented 8 years ago

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.

tacone commented 8 years ago

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.

CHOMNANP commented 8 years ago

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

Thank Tacone.