F
F
frontendo2017-06-10 20:17:57
Laravel
frontendo, 2017-06-10 20:17:57

Is it possible to break application execution from model code?

Interested in this question. For example, a request came to the user profile, id is naturally passed, the controller makes a request to the model, the model does not find the user by id in the database, is it possible to do abort (404) directly in the model?
What is it all for? There are several routes -> methods in the controller that access the same model, and each of them can receive a request for a non-existent user. So, in order not to write if (!$user) abort(404); in each controller method; could be written once in the model

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2017-06-10
@frontendo

IMHO this is not Christian, to create states from the model, the controller does this, the model should not know about the states. This may be normal for Laravel, but in general it violates single responsibility.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question