Create Controller in a specific folder in Laravel?

Asked

Viewed 1,849 times

2

I’m with a little doubt that came to me, I’m learning Laravel, and so far to create a controller I used the command php artisan make:controller, he leaves the controller in the briefcase Controller in the file structure, but I want to create a controller in another folder to organize the files, and simply crop does not work, or the command php artisan make:controller pasta/control --resource neither will, someone help me with this doubt?

2 answers

2

Wraps double folder quotes and controller that works:

$ php artisan make:controller "Utils\SpaceController" --resource

where Utils is a folder created and the SpaceController own controller.

Documentation - Controllers

If you change yours controller manual form, should also update this namespace and that’s why it doesn’t work.

1

Basque set the directory where you want to create the controller, for example:

php artisan make:controller test/testController

The controller will be created inside the directory test/

If you have already created and wanted to move it, you will need to reset the namespace so that it fits to the directory where it is.

For example, if you created on the root of Controllers namespace will be like this: namespace App\Http\Controllers; just move to the test folder and add to the namespace the new path, for example: namespace App\Http\Controllers\test;

References: https://laravel.com/docs/5.7/structure

  • Thanks Bulfaitelo, helped me basntante!

  • 1

    @Micheldiniz if the answer helped solve your problem, mark as solved the problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.