Laravel Artisan CLI:如何使用make命令包含命名空间


Laravel Artisan CLI: How to include namespace with make command?

使用Laravel 5.1,我试图运行这样的命令

php artisan make:controller Auctions'AuctionController

我的期望是它将在app/Http/controllers/Auctions/目录中创建AuctionController.php文件,如下所示:

app/Http/controllers/Auctions/AuctionController.php

但是,该命令在app/Http/Controllers/目录下创建了一个名为AuctionsAuctionController.php的文件:

app/Http/Controllers/AuctionsAuctionController.php

make:[method]引用命名空间的正确方法是什么?

你需要一个正斜杠而不是反斜杠:

php artisan make:controller Auctions/AuctionController

使用双反斜杠

php artisan make:controller Auctions''AuctionController

在终端中,单个反斜杠用于转义下面的字符,例如,您可能希望在文件名中使用空格,但显然,终端中的空格用于分隔参数,因此您可以使用反斜杠来允许使用空格。

例如,在终端上运行touch test' file将创建一个名为test file的文件。如果您想在文件名中使用反斜杠(无论出于何种原因),同样适用,使用双反斜杠touch test''file,然后创建一个名为test'file

的文件。