I'm learning how to use Laravel 5 and I've ran into a problem where my controllers are being created in the root of the "app" folder instead of the "controller" folder. I have no idea why this is happening as I've re installed and checked 10 times.
I'm in gitbash on windows 8.1..
So I go
john@John ~/desktop/code/my-first-app
$ php artisan make:controller PagesController
and then I get
Controller created successfully
Only it's being created in the root of app
and nothing in the Controllers folder. What am I missing? I also see others having the same problem in comments under video on laracasts.
Controllers can group related HTTP request handling logic into a class. Controllers are typically stored in the app/Http/Controllers directory.
Open the command prompt or terminal based on the operating system you are using and type the following command to create controller using the Artisan CLI (Command Line Interface). Replace the <controller-name> with the name of your controller. This will create a plain constructor as we are passing the argument — plain.
The " / " is special location and you can set it via Route::get('/','home@index') . For all other actions on home controller you will have urls such has " /home/action1 " or " /home/action2 ". I am just trying to make you understand that there is no benefit and need of making any controller assign to " / ".
The controller can be created into specific path as followed:
php artisan make:controller controllerName
However, if you would like to create it in a custom directory then refer to the line below:
below will create on root path (outside app directory)
php artisan make:controller App\\../pathName/controllerName
If want inside app directory then it should be
php artisan make:controller App\\pathName/controllerName
Tested on Laravel 6.x
In Laravel 5, it is not required to specify the path. By default, it will generate the controller in the directory.
So, the controller can be created like this:
php artisan make:controller controllerName
However, if you would like to create it in a custom directory then refer to the line below:
php artisan make:controller pathName/controllerName
After trying php artisan make:controller Directory\PageController
, Laravel 5.1 would create a controller named DirectoryPage Controller in my app directory. The solution for me was to escape the backslash with another backslash so the following worked for me:
php artisan make:controller Directory\\\\PageController
Laravel created a Pagecontroller in the app/Directory
. Just thought I would share with everyone.
php artisan make:controller -r controllerName
Try it with -r option it will create controller with boiler plate (All the basic function like: - public function index(){}, public function store(Request $request){}, and so on...... for better understanding you can also visit: - https://laracasts.com/series/laravel-from-scratch-2017
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With