F
F
freelancer0072020-08-13 00:50:37
Laravel
freelancer007, 2020-08-13 00:50:37

How to catch Laravel exception?

Hello!
I can’t understand why try catch doesn’t catch the exception, maybe I don’t understand correctly and laravel doesn’t throw an exception of the ModelNotFound type in my case.

// id Компании (компания с таким id есть в базе)
// user_id - Это id пользователя который добавил компанию
// Я намеренно у запрашиваемой модели компании в базе поменял user_id на id другого пользователя
try {
            Company::where('id', $id)
                ->where('user_id', Auth::id())
                ->get();
        } catch (Exception $exception){
            //Тут действия по обработке
        }

I expect that if a model with the given criteria is not found, it will throw an exception, but this does not happen. Prompt knowing chyadnt?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2020-08-13
@freelancer007

chyadnt?
You don't read the documentation .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question