【问题标题】:Get url pattern in middleware's handle method in laravel在 laravel 的中间件的句柄方法中获取 url 模式
【发布时间】:2016-09-09 08:41:31
【问题描述】:

在 routes.php 中,我将路由定义为

Route::get('entities/{id}/queries','QueryController@fetch');

实际的示例网址是(例如):http://localhost:8000/entities/5/queries

public function handle($request, Closure $next, $guard = null) {
   echo $request->path(); //returns entities/5/queries
   return $next($request);
}

现在我需要在中间件中访问该 url 模式。 即 entities/{id}/queries。 有没有返回url模式的方法?

【问题讨论】:

    标签: laravel routes middleware


    【解决方案1】:

    您可以通过使用 $request 对象中的路由来做到这一点。

    像这样:

    $request->route()->uri();

    这将在您的情况下返回 entities/{id}/queries

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-22
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-15
      相关资源
      最近更新 更多