I have a model Mailgroup with a one to many relation for Individual.
Now when I create a new Individual I want to make sure that that Individual is unique for that specific mailgroup.
In my form validation I did this:
'individual_email' => 'required|unique:individuals|max:255',
This works good but it checks the entire database so if that individual exist for 1 mailgroup it will says that it's already in use.
Now I read in the laravel documentation you can add where clausules in your validation like this:
'email' => 'unique:users,email_address,NULL,id,account_id,1'
In the rule above, only rows with an account_id of 1 would be included in the unique check.
So I wanna change my rule to something like this:
'individual_email' => 'required|unique:individuals,individual_email,NULL,id,mailgroup_id,'.$data['mailgroup_id'].'|max:255'
But the problem is how can I access my form post data? because $data is not recognized.