G
G
ganbatte2019-06-23 13:12:59
Laravel
ganbatte, 2019-06-23 13:12:59

How can I make PHP not display its own error, but only my written error?

I have created a form to add data to a table. 1 column is unique, that is, the primary key. When I add the same key that exists, I get this error

Illuminate \ Database \ QueryException (23000)
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'test' for key 'PRIMARY' (SQL: insert into `type` (`type`, `description`) values (test, asdfasf))

How do I avoid this error, but instead my edited error, like(' this type already exists') ? Made it in Laravel.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
JhaoDa, 2019-06-23
@JhaoDa

How to do
Just like it says in the documentation .

K
Konstantin B., 2019-06-23
@Kostik_1993

Throw your Exception
But in your case, as I understand it, the question is different, you just need to validate the data on a unique value, and since the decision about validation came to my mind, and not yours, I strongly recommend that you study the documentation

J
jazzus, 2019-06-23
@jazzus

Form Request Validation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question