Get last part of current URL in Laravel 5 using Blade

Ronald Zwiers picture Ronald Zwiers · Jun 19, 2016 · Viewed 37.7k times · Source

How to get the last part of the current URL without the / sign, dynamically?

For example:

In www.news.com/foo/bar get bar.

In www.news.com/foo/bar/fun get fun.

Where to put the function or how to implement this in the current view?

Answer

user2094178 picture user2094178 · Jun 20, 2016

Of course there is always the Laravel way:

request()->segment(count(request()->segments()))