Answer the question
In order to leave comments, you need to log in
What is the best way to initialize a class in Laravel so that its methods and variables are available everywhere?
We created a class that has an array - this is a list of error codes and messages, as well as a method that issues a message by the error code and returns it in the form
return response()->json(
.......
);
and how would it be better to do so that you can call this line in all controllers like
return $this->responser->getReturnData($ErrorCode);
You can override the constructor in each controller and start a class object there using new
$this->responser = new RectonderClass;
and then in each method refer to the class object and its method. But are there better methods?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question