简体   繁体   中英

How to create controller inside folder app but outside folder http in laravel?

I have a folder Web inside folder app of Laravel. And i want to create Controller inside folder Web. But when i run commandline :

$ php artisan make:controller app/Web/Controllers/Webcontroller

It create controller inside folder Http/Controllers as default. So how to do that?

You could try this:

php artisan make:controller ../../App/Web/Controllers/WebController

or create the controller manually as Jerodev suggests in the comments of the question.

What laravel suggest is 

It is very important to note that we did not need to specify the full controller namespace when defining the controller route. Since the RouteServiceProvider loads your route files within a route group that contains the namespace, we only specified the portion of the class name that comes after the App\Http\Controllers portion of the namespace.

If you choose to nest your controllers deeper into the App\Http\Controllers directory, use the specific class name relative to the App\Http\Controllers root namespace. So, if your full controller class is App\Http\Controllers\Photos\AdminController, you should register routes to the controller like so:

Route::get('foo', 'Photos\AdminController@method');

so if you create your controller out side Controllers directory you may have to do extra work for it to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM