如何在laravel的文件夹应用程序内部但文件夹http外部创建控制器?

时间:2019-08-26 09:25:54

标签: php laravel

我在Laravel的文件夹应用程序中有一个文件夹Web。而且我想在文件夹Web中创建Controller。但是当我运行命令行时:

  

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

默认情况下,它在文件夹Http / Controllers中创建控制器。那怎么办呢?

2 个答案:

答案 0 :(得分:1)

您可以尝试以下方法:

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

或按照Jerodev在问题注释中的建议手动创建控制器。

答案 1 :(得分:0)

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.
相关问题