0
Good night, you guys. I’m having trouble returning a friendly error message to the user if he tries to register an employee with an email that is already saved in the database, since in my table this attribute was "set" as Unic.
Can anyone tell me how to customize this on Laravel 5.6? Currently is returning the default error message that is this one:
Illuminate Database Queryexception (23000)
SQLSTATE[23000]: Integrity Constraint Violation: 1062 Duplicate entry '[email protected]' for key 'funcionarios_email_funcionario_unique'
I would like to put a message in the view itself for the user, like this:
"Email already registered in the database!"
The way of exception is this one:
..vendorLaravel framework src Illuminate Database Connection.php
And that’s the exception treatment:
protected function runQueryCallback($query, $bindings, Closure $callback)
{
// To execute the statement, we'll simply call the callback, which will actually
// run the SQL against the PDO connection. Then we can calculate the time it
// took to execute and log the query SQL, bindings and time in our memory.
try {
$result = $callback($query, $bindings);
}
// If an exception occurs when attempting to run a query, we'll format the error
// message to include the bindings with SQL, which will make this exception a
// lot more helpful to the developer instead of just the database's errors.
catch (Exception $e) {
throw new QueryException(
$query, $this->prepareBindings($bindings), $e
);
}
return $result;
}
you are not using the Redeemable Validate?
– Ademilson Santana da Silva
No. The validate would be a Laravel Feature?
– DevPHP
Yes, you define which form fields you want to validate and which type of validation you will use. the following doc: https://laravel.com/docs/5.7/validation#Quick-writing-the-validation-Logic
– Ademilson Santana da Silva