Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the lastest slug from url in Laravel

Tags:

php

laravel

slug

This is my route:

Route::get('{slug?}/{slug2?}/{slug3?}', 'PageController@show');

This is how I got the slug value in my service provider:

$this->app->request->route('slug2')

Somethings my url looks like base_url/slug or base_url/slug/slug2 or base_url/slug/slug2/slug3. I am looking for a laravel way to get the lastest slug always no matter how my url looks like. Is there a way to do that ?

Thx

like image 579
Attila Naghi Avatar asked Dec 11 '25 17:12

Attila Naghi


1 Answers

Using this I can get the lastest slug from my url. But I am still looking for a better solution even If i have to change the route. This is the code:

use Illuminate\Support\Facades\Request;
....
Request::segment(count(Request::segments()))
like image 156
Attila Naghi Avatar answered Dec 13 '25 06:12

Attila Naghi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!