In Laravel 5, how can I move the controllers out of the 'app' folder
I am placing all the classes codes in a separate folder. I have created a folder 'src' alongside the folder 'app'. Within this 'src' folder will be 'Models', 'Views' and 'Controllers' folder and 'routes.php' file too. So the scructure will be as follows.
- app
- src
- Controllers
- Models
- Views
- routes.php
I have moved the routes.php and views to src by changing the routing path in 'app\Providers\RouteServiceProvider.php' and view path in 'config/view.php'. Please correct me if I did anything wrong here.
My question is - how can I move controllers, models, views and route.php from app to src?
I want to do this because I want to palce all the user written codes in one place. I don't want to move the app/Http/Controllers/Controller.php. I just want to move the user created controllers.
I want to achive this without braking anything at other places.
Answer
You can move your code there, you'll just need to tell autoloader where to find those classes. You'll need to update autoload section in your composer.json.
What namespace are your controllers in? It will impact what you need to put there. If you store them in \App\Http\Controllers, you'll need to add the following there:
"autoload": {
"classmap": [],
"psr-4": {
"App\\Http\\Controllers\\": "src/Controllers/",
}
},
This will tell autoloader that the root directory for App\Http\Controllers namespace is src/Controllers/ folder.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?