Reputation: 537
I have a table 'user_temps' which contains the new user until they confirmed their subscription. Once done, i copy the user to the 'users' table.
In the registration form i have this validation params :
'email' => 'required|email|max:255|unique:user_temps|unique:users',
The problem is there I need to have 2 different messages : if the user is in the 'user_temps' table and another one if the user is in the 'users' table.
Thank you
Upvotes: 0
Views: 2080
Reputation: 537
After trying some bad solutions someone (tank you pmall) gave me the answer in another place :
I defined my own validator for the temporary user
public function validateTempUserEmail($attribute, $value, $parameters)
{
return UserTemp::where($attribute, $value)->count() == 0;
}
And now the rule for validate the email is
'email' => 'required|email|max:255|TempUserEmail|unique:users',
Upvotes: 1
Reputation:
To simplify things, could you not do the following:
In your user's table, have a boolean column named 'subscribed' defaulted to 0. Then when they've confirmed their subscription you could set it to 1?
Then, upon authentication, you can run this check:
if (Auth::attempt(['email' => $email, 'password' => $password, 'subscription' => 1]))
{
// The user is active, subscribed and exists.
}
Upvotes: 0
Reputation: 5443
you can set custom validation message
$rules = array(
'email' => 'required|email|max:255|unique:user_temps|unique:users'
);
$messages = array(
'email.required' => 'Email is required',
'email.email' => 'Email need to be email type',
'email.unique:user_temps' => 'This email is already exists in user temps table',
'email.unique:users' => 'This email is already exists in users table',
);
$validator = Validator::make(Input::all(), $rules, $messages);
Upvotes: 1