简体   繁体   English

控制器外部的 Laravel 访问请求对象

[英]Laravel access request object outside controller

According to the Laravel documentation Request is acquired via dependency injection.根据 Laravel 文档,请求是通过依赖注入获得的。 For a controller this is fine, but how do we access Request object outside a controller, for example in a view对于控制器来说这很好,但是我们如何访问控制器外部的请求对象,例如在视图中

There is request helper in laravel. laravel 中有请求助手。 You can use Request Object anywhere.您可以在任何地方使用请求对象。 For example例如

request()->field_name 

Here's laravel documentation link for request helper https://laravel.com/docs/5.2/helpers#method-request这是请求帮助程序的 laravel 文档链接https://laravel.com/docs/5.2/helpers#method-request

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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