Query the database to see if that username is already in use, if so, display a message to user to select another name.
Jun 12, 2015
3
Level 2
What's the best way to handle sql error, as validation error?
For example, I can use validator for user register. But if I set username column is unique, when it passed validate then will got a sql error caused by unique.
I know I can use try catch to catch that error, but how can I got the errors like $this->validate() method failed return?
Thanks!
Level 11
use the unique validation rule. The only way the DB would throw an error due to the column being unique() would be if validation is bypassed.
http://laravel.com/docs/5.1/validation#rule-unique
'username' => 'unique:users,username'
Please or to participate in this conversation.