在 laravel 中,我遇到了需要从 url 获取路径名的情况。
例如
www.example.com/timeslot
在上面的例子中,我想在我的控制器中获取“时间段”
public function login()
{
$url = URL::current();
echo "timeslot"; //I want to print only "timeslot" here.
}
Run Code Online (Sandbox Code Playgroud)
你好在laravel中检索一个uri段使用它
$segment = Request::segment(1);
Run Code Online (Sandbox Code Playgroud)
像这样的刀片视图内部
{!! Request::segment(1) !!}
Run Code Online (Sandbox Code Playgroud)
这将返回您的项目 uri 的第一部分
www.example.com/timeslot
时隙
简单地使用
$request->path();
Run Code Online (Sandbox Code Playgroud)
path 方法返回请求的路径信息。因此,如果传入请求的目标是www.example.com/timeslot,则路径方法将返回timeslot。
请参阅:https : //laravel.com/docs/5.4/requests