How to access URL segment(s) in blade in Laravel 5?

前端 未结 6 730
滥情空心
滥情空心 2021-02-03 17:43

I have a url : http://localhost:8888/projects/oop/2

I want to access the first segment --> projects

I\'ve tried

6条回答
  •  遇见更好的自我
    2021-02-03 18:03

    An easy way to get the first or last segment, in case you are unsure of the path length.

    $segments = request()->segments();
    $last  = end($segments);
    $first = reset($segments);
    

提交回复
热议问题