Laravel 5.0将变量传递给中间件 [英] Laravel 5.0 pass variable to middleware

查看:101
本文介绍了Laravel 5.0将变量传递给中间件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻,我必须检查正在编辑的工作记录是否属于合适的人.我的求职编辑路线:

At the moment I have to check if job record, which is being edited, belongs to right person. My get job edit route:

/user/job-edit/{slug}

所以我创建了JobEditMiddleware,但是问题是我无法在Middlewar中访问{slug}变量.有什么办法吗?谢谢.

So I created JobEditMiddleware but the problems is I can't access {slug} variable in my middlewar. Is there any way to do it? Thanks.

推荐答案

您可以使用segment()方法来检索URI的各个段.

You can use segment() method to retrieve various segments of your URI.

尝试在您的中间件中关注

Try following in your middleware,

\Request::segment(3)

了解详情

这篇关于Laravel 5.0将变量传递给中间件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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