Laravel 5 make: controller that creates the controller in the application folder instead of the controller folder

I am learning how to use Laravel 5, and I ran into a problem when my controllers are created in the root of the app folder instead of the controller folder. I have no idea why this is happening since I 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 is created in the root directory of the app and nothing in the Controllers folder. What am I missing? I also see that others have the same problem in the comments on the video on laracasts .

+8
source share
5 answers

In Laravel 5 there is no need to specify a path. By default, it will generate a controller in the directory.

So, the controller can be created as follows:

 php artisan make:controller controllerName 

However, if you want to create it in a custom directory, refer to the following line:

 php artisan make:controller pathName/controllerName 
+30
source

After trying php artisan make:controller Directory\PageController Laravel 5.1 will create a controller named DirectoryPage Controller in the directory of my application. The solution for me was to avoid the backslash with another backslash, so the following worked for me:

 php artisan make:controller Directory\\\\PageController 

Laravel created a Pagecontroller in app/Directory . Just thought I'd share it with everyone.

+2
source

There seems to be a mistake in creating the controllers.

I checked it a minute ago using Laravel 5, which I installed in about a week or two, and it worked fine. But when I installed the new Laravel 5, now the controllers are created in the app/ folder, and not in app/Http/Controllers .

But it’s also possible that the developers changed their minds where the controllers will be stored (Laravel 5 is still under development).

No one currently knows this, you can also watch the Laracast discussion about this issue.

It is also strange that you cannot manually add the path to this command.

In Laravel 4 you can do:

 php artisan controller:make --path="app/Controllers" PagesController 

but in Laravel5 for controller:make you have fewer options compared to Laravel 4, they are:

 Options: --plain Generate an empty controller class. --help (-h) Display this help message. --quiet (-q) Do not output any message. --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --version (-V) Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction (-n) Do not ask any interactive question. --env The environment the command should run under. 

therefore, you cannot put your own path here or create some methods, as you can in Laravel 4.

EDIT

It seems to work again, as in the latest Laravel 5 commit. Therefore, you must either create a new Laravel 5 project or run:

 composer update 

to update the project.

However, you will probably get some errors, for example:

{"error": {"Type": "Symfony \ Component \ Debug \ Exception \ FatalErrorException", "message": "Class 'Illuminate \ Routing \ FilterServiceProvider' not found", "file":

To remove these errors:

in the file app/Providers/FilterServiceProvider.php change

 use Illuminate\Routing\FilterServiceProvider as ServiceProvider; 

in

 use Illuminate\Foundation\Support\Providers\FilterServiceProvider as ServiceProvider; 

and in the file in the file app/Providers/RouteServiceProvider.php change

 use Illuminate\Routing\RouteServiceProvider as ServiceProvider; 

in

 use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; 
0
source

Make an update for the composer and it will be normal.

0
source

php artisan make: controller -r controllerName

Try with the -r option, it will create a controller with a boiler plate (the whole main function is like: - public function index () {}, public function store (Request $ request) {}, etc ... for a better understanding You can also visit: - https://laracasts.com/series/laravel-from-scratch-2017

0
source

Source: https://habr.com/ru/post/1203696/


All Articles