如何在 laravel 5 的命名空间路径中生成 laravel 请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26440220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:17:59  来源:igfitidea点击:

How to generate laravel request in namespace path for laravel 5

phplaravellaravel-5

提问by matthewdaniel

I'm familiar with the laravel artisan command

我熟悉 laravel artisan 命令

make:request

制作:请求

however I can't seem to get it to place it in a directory. For example I have a directory structure

但是我似乎无法将它放在目录中。例如我有一个目录结构

app/Http/Requests/User

应用程序/Http/请求/用户

and I'd like to place a request in that folder namespaced appropriately but

我想在命名空间适当的文件夹中放置一个请求,但是

php artisan make:request User\CreateUserRequest 

doesn't work.

不起作用。

回答by matthewdaniel

artisan make:request User\\CreateUserRequest

artisan make:request User\\CreateUserRequest

thanks to @DarrylCoderfor answering in the comments

感谢@DarrylCoder在评论中回答

回答by Jason

Switch the slash (/) direction to forward:

将斜杠 ( /) 方向切换为向前:

php artisan make:request User/CreateUserRequest 

回答by Marcin Nabia?ek

Make sure you have in your composer.json:

确保你有composer.json

"autoload": {
    "classmap": [
        "database",
        "tests/TestCase.php"
    ],
    "psr-4": {
        "App\": "app/"
    }
},

You should have this part psr-4(it's set by default here) .

你应该有这部分psr-4(这里是默认设置的)。

Now you should rather don't use app/Requests/Userbut app/Http/Requests/Userbecause Requestsshould be placed in Httpdirectory.

现在你应该宁可不使用app/Requests/Userapp/Http/Requests/User因为Requests应该放在Http目录中。

Now when you run php artisan make:request User\CreateUserRequestyou should get response from artisan:

现在,当您运行时,php artisan make:request User\CreateUserRequest您应该得到工匠的响应:

\Request created successfully.

\请求创建成功。

and in your app/Http/Requests/Userdirectory you should have file CreateUserRequest.php

在你的app/Http/Requests/User目录中你应该有文件CreateUserRequest.php

I've checked it a moment ago and it works fine. Of course it's possible that in the version you have installed you have a bug or you changed some other app settings so you could try update it to the newest version (I've tested it on version I've downloaded a couple days ago).

我刚刚检查过它,它工作正常。当然,您安装的版本可能存在错误,或者您更改了一些其他应用程序设置,因此您可以尝试将其更新到最新版本(我已经在几天前下载的版本上对其进行了测试)。

回答by im-sunil

php artisan make:request Auth\\CreateUserRequest

php artisan make:request Auth\\CreateUserRequest

that will make request file in Requests\Authfolder

这将使文件Requests\Auth夹中的请求文件

OR

或者

php artisan make:request Auth/CreateUserRequest

php artisan make:request Auth/CreateUserRequest