R
R
Roman2019-04-24 00:24:46
Laravel
Roman, 2019-04-24 00:24:46

When do you need to inherit Controller?

Hello.
I periodically create classes that are neither models nor controllers - i.e. they just contain all sorts of utility functions.
But by inertia, I create them through artisan make:controller :-) and, accordingly, it inherits the Controller class
. And I suspect that this is not always necessary ))
What do I get from the Controller class in my controllers?
For example, dependency injection into a function - is it from him?
How to understand where I need it and where not?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konata Izumi, 2019-04-24
@procode

I periodically create classes that are neither models nor controllers - i.e. they just contain all sorts of utility functions.

You create service classes.
Work with requests and responses, sessions, cookies, etc.
No, it works throughout the Laravel application. You can define your class and use DI there.
If your class does not contain work with requests and responses, then it makes no sense to inherit from Controller.
You can poke around inside the controller's base class to see what it contains. It won't be redundant.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question