2

I want to get the last word of this URL:

http://localhost:8888/articles/tags/Europa

How could I make this in Laravel ? with this {{URL::current()}} I'm getting full URL. I have tried {{URL::current().split('/').last}} but then I get error: Function split() is deprecated

frenchbaguette
  • 1,297
  • 6
  • 22
  • 41

2 Answers2

7

You can also use segment method of the Request class.

$var = Request::segment(3);

This will capture the 3rd segment of the URI according to the API docs: http://laravel.com/api/5.1/Illuminate/Http/Request.html#method_segment

josh088
  • 121
  • 1
  • 7
1

Try and use preg_split() instead

Example:

$var = 'http://localhost:8888/articles/tags/Europa';
$var = preg_split("/\//", 'http://localhost:8888/articles/tags/Europa');
array_pop($var ); //removes last

Update

I can't delete this because it is the accepted answer but please see josh088's answer

Community
  • 1
  • 1
JayIsTooCommon
  • 1,714
  • 2
  • 20
  • 30