M
M
Muhammad2015-05-04 19:54:49
Laravel
Muhammad, 2015-05-04 19:54:49

Breaking a call chain in Laravel?

Good evening. For example, there is a controller HomeController , it calls the methodA method of class A , which, in turn, calls the methodB method of class B and so on up to class X. If everything is ok, then the methodX method generates a response that is passed along the chain back to the Home controller. In addition, each method performs some kind of manipulation with this data (or returns other data). But, if an error occurs, the class generates an object (eg ErrorClass ) with the error and some additional parameters, which must be serialized and returned as a Response.
The problem is that when passing through this chain, you will have to check whether the method's response is an instance of ErrorClass . Of course, you can do this:

echo serialize($object);
die();

, but that's not what you need. If it was just text, I would throw an exception, but here you need to somehow pass the object to the HomeController.
I hope I explained clearly. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Muhammad, 2015-05-04
@muhammad_97

Solved the problem by inheriting from Exception. Now I'm just throwing an exception

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question