Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 make:controller creating controller in app folder instead of controller folder

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.

like image 742
user300979 Avatar asked Sep 30 '14 09:09

user300979


People also ask

Where is the controller folder in Laravel?

Controllers can group related HTTP request handling logic into a class. Controllers are typically stored in the app/Http/Controllers directory.

How do I manually create a controller in Laravel?

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.

Where is the default controller in Laravel?

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 " / ".


4 Answers

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

like image 23
Surjit Sidhu Avatar answered Oct 21 '22 06:10

Surjit Sidhu


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
like image 176
Vijay Sebastian Avatar answered Oct 21 '22 06:10

Vijay Sebastian


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.

like image 36
Matthew Way Avatar answered Oct 21 '22 05:10

Matthew Way


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

like image 40
Jitesh Lakhwani Avatar answered Oct 21 '22 06:10

Jitesh Lakhwani