FavoriteLoadingAdd to favorites

A Controller or Class in MVC are both just classes.
So… Technically speaking.
It is possible to write all your functionality inside your controllers and completely ditch the classes folder.
But! The purpose of breaking out into separate classes is re-usability.

Controllers :


namespace App\Http\Controllers;

class MyCustomController extends Controller


Classes :


namespace App\Classes\MyCustomClass;

class ClassNameWhateverWhatever


Why Classes, what is the point?
Classes serve as containers for specific purposes.
For example.

You create a class for :

And inside your class you write all your functionality.
A car can have specific functionality.


Then, you reference your car class inside your contollers.

So something like

This design strategy makes your code extremely easy to re-use without having to re-write additional functionality. This is why we seperate everything into a class and then we create another class called a controller class and reference our classes inside the controller classes.

Pin It on Pinterest

Share This