请求(外观)和 Illuminate\Http\Request 之间的区别
Difference between Request (Facade) and Illuminate\Http\Request
我开始使用 Laravel,我想知道我应该如何选择其中之一。
从 5.0 版开始 Laravel 文档将请求示例从 Request::get('form_input')
更改为 $request->get('form_input')
,但我找不到关于他们为什么这样做的任何解释。
我的疑惑是:
- 那些
Requests
有什么区别吗?
- 它们是什么?
- 最喜欢什么?
直接回答:否(具体区别)
除了:从这个来源引用,How laravel facades work and how to use
A Laravel facade is a class which provides a static-like interface to services inside the container. These facades, according to the documentation, serve as a proxy for accessing the underlying implementation of the container’s services.
我非常同意这一点。但对我来说,使用门面模式 只是让我的代码更干净 :)
Request facade 和 request() 助手都引用了 app('request') 实例。
我认为文档中的示例已更改为 $request,因为您可以定义自己的派生请求 class,并且服务容器会自动将其注入到操作调用中,就像 FormRequest 的情况一样,即:
public function store(UserStoreRequest $request)
{
$name = $request->input('name');
我开始使用 Laravel,我想知道我应该如何选择其中之一。
从 5.0 版开始 Laravel 文档将请求示例从 Request::get('form_input')
更改为 $request->get('form_input')
,但我找不到关于他们为什么这样做的任何解释。
我的疑惑是:
- 那些
Requests
有什么区别吗? - 它们是什么?
- 最喜欢什么?
直接回答:否(具体区别) 除了:从这个来源引用,How laravel facades work and how to use
A Laravel facade is a class which provides a static-like interface to services inside the container. These facades, according to the documentation, serve as a proxy for accessing the underlying implementation of the container’s services.
我非常同意这一点。但对我来说,使用门面模式 只是让我的代码更干净 :)
Request facade 和 request() 助手都引用了 app('request') 实例。 我认为文档中的示例已更改为 $request,因为您可以定义自己的派生请求 class,并且服务容器会自动将其注入到操作调用中,就像 FormRequest 的情况一样,即:
public function store(UserStoreRequest $request)
{
$name = $request->input('name');