In the previous chapters we explained how to create a background folder in the Laravel framework.
PHP laravel Framework Setup Background folder
Now we're going to add a piece of content. It's about the automatic loading section.
There is also a start directory in our app directory. It reads:
In addition to using Composer, the Laravel class loader to
Load your controllers and models. This is useful to keeping all
Your classes in the "global" namespace without Composer updating.
In addition to using composer, you can also use the Laravel classloader to load your controller and model.
This is useful for your class to be in the global namespace without the use of composer updating.
We have a code fragment here.
Classloader::adddirectories Array (
App_path (). ' /commands ',
App_path (). ' /controllers ',
App_path (). ' /controllers/admin ',
App_path (). ' /models ',
App_path (). ' /database/seeds ',
));
Yes, very familiar, these folders are the folders that we often use, controllers, commands. Model, database Seed
The contents of these folders can be automatically loaded into the global namespace.
But there's one more thing I'm commenting on. What is the purpose of this content?
is to let us in the controllers directory the controller in admin also has the global namespace. So we can go directly to the routing table.
Our controller name came in to receive it.
I tested it, did it, and no longer needed compoer dumpautoload
But there's still a problem, what if there's a controller in the Admin folder that's the same as the outside name?
I have also done an experiment, and finally found that it will only choose one of them, as to exactly which one to choose, it depends on the order of the loading above us.
If it is
App_path (). ' /controllers ',
App_path (). ' /controllers/admin ',
Then the external controller is valid, otherwise the controller inside the Admin folder is valid.
The combination was written so much before. In fact, the most insurance, but also tall way is to use the name space.
But it would be a little more complicated to write. Small projects can be considered in our approach. Big deal, don't let these controllers conflict.
There's no way to control it.
Do one thing in a Time,and do.
Best Wishes.