如何在Laravel 5中从请求中检索url参数? [英] How to retrieve a url parameter from request in Laravel 5?

查看:150
本文介绍了如何在Laravel 5中从请求中检索url参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对中间件中的模型执行某些操作.这是我要实现的示例:

I want to perform certain operations with a model in a middleware. Here is an example of what I want to achieve:

public function handle($request, Closure $next)
{
    $itemId = $request->param('item'); // <-- invalid code, serves for illustration purposes only
    $item   = Item::find($itemId);

    if($item->isBad()) return redirect(route('dont_worry'));

    return $next($request);
}

我的问题是,如何从$request检索所需的参数?

My question is, how can I retrieve the desired parameter from the $request?

推荐答案

public function handle(Request $request, Closure $next)
{
    $itemId = $request->item;
    //..............

}

这篇关于如何在Laravel 5中从请求中检索url参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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