27
loading...
This website collects cookies to deliver better user experience
app/Http/Controllers
directory might get cluttered with too many Controllers.app/Http/Controllers
directory.artisan
command:php artisan make:controller DemoController --resource
Note: in case that you are not familiar with the --resource
flag, all that it does is to create a controller with all methods needed for your CRUD.
app/Http/Controllers/
directory.php artisan make:controller Demo/DemoController --resource
Demo
directory:app/Http/Controllers/Demo/DemoController.php
Note that we use a slash /
to separate our namespace with our controller.
app/Http/Controllers/
directory but instead organize them in a more suitable for you way.index
method with a simple return statement. With your text editor of choice, open the app/Http/Controllers/Demo/DemoController.php
and update your index
method as follows:public function index()
{
return "Custom Namespaces are awesome!";
}
routes/web.php
file and add the following:Route::namespace('Demo')->group(function() {
});
namespace
method, we can specify the new custom Demo
namespace.Route::namespace('Demo')->group(function() {
Route::resource('demo', DemoController::class);
});