Agus Sumawigena
Agus Sumawigena

Reputation: 73

how to get url segments count in laravel 5?

I have following Route,

http:/localhost/seg1/seg2/seg3

how to get Request::segment count from the url above ?

Expected result is,

$totalSegsCount = 3

Thanks,

Upvotes: 4

Views: 5261

Answers (1)

Quezler
Quezler

Reputation: 2435

The Request object has a function that returns all segments, place that in a count() to get the number you seek:

$totalSegsCount = count(Request::segments());

Upvotes: 9

Related Questions