Laravel控制器外部的访问请求对象 [英] Laravel access request object outside controller

查看:70
本文介绍了Laravel控制器外部的访问请求对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Laravel文档,请求是通过依赖注入获得的.对于控制器,这很好,但是我们如何访问控制器外部的Request对象,例如在视图中

According to the Laravel documentation Request is acquired via dependency injection. For a controller this is fine, but how do we access Request object outside a controller, for example in a view

推荐答案

laravel中有请求帮助器.您可以在任何地方使用请求对象. 例如

There is request helper in laravel. You can use Request Object anywhere. For example

request()->field_name 

这是laravel文档链接,用于请求帮助程序 https://laravel.com/docs/5.2/helpers#method-request

Here's laravel documentation link for request helper https://laravel.com/docs/5.2/helpers#method-request

这篇关于Laravel控制器外部的访问请求对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆