Table of contents
01: .
02: βββ Controllers
03: β βββ Map
04: β β βββ MainController.php
05: β βββ Blog
06: β βββ Book
07: β βββ Controller.php
Creating the subfolder
Placing your controller in a subfolder starts by actually placing the controller in the folder. The folder structure above shows the controller MainController
placed in the Map
folder.
Updating the namespace
Once you are done with that the next thing to do is update the namespace to reflect this change. Thus:
01: <?php
02:
03: namespace App\Http\Controllers\Map;
Updating references
Next, since your controller extends the base controller i.e: Controller.php
we might need to update the reference to that as well.
If you use anything from Laravel 9 you will certainly need to update this reference.
01: <?php
02:
03: namespace App\Http\Controllers\Map;
04:
05: use Illuminate\Http\Request;
06: use App\Http\Controllers\Controller as ParentController;
07:
08: class MainController extends ParentController
09: {
10: ...
On line 06
we explicitly import the base controller and alias it as ParentController
, we then extend our controller using the alias on line 08
.
Here is another article you might like π Laravel file driven cache on steroids