如何使用 Laravel 5.4 从控制器中的路由文件获取实际路由路径

How can I get Actual Route path From Route file in controller using Laravel 5.4

如何使用 Laravel 5.4

从控制器中的路由文件中获取实际路由路径

当我使用 $url =$request->route()->getPath(); 时,在 laravel 5.4

中出现错误消息

这样的消息:

  • local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Illuminate\Routing\Route::getPath() in E:\xampp\htdocs\newneptune\app\Http\Middleware\rollwise.php:25 Stack trace:

使用getPathInfo():

$request->getPathInfo();

它将 return URI 没有 GET 参数如果有的话。

使用Route::getCurrentRoute()->getUri()

希望对您有所帮助。

而不是 $request->route()->getPath() 使用 $request->route()->uri()