I have a App where I want the combination of three fields: rollyear
, rollfaculty
and rollno
in a table to be unique. For that, I did the following in the migration file:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email');
$table->string('rollyear');
$table->string('rollfaculty');
$table->string('rollno');
$table->unique(['rollyear','rollfaculty','rollno']);
});
This is working as expected but whenever duplicate values are supplied to the specified fields, I get a full page Integrity constraint violation error.
How can I handle this error and give a simplified error message to the user as in following image?