3

I want route like:

Route::get('/{slug}/{slug-2}/{slug-3}/../{slug-n}', ['as' => 'slug',   'uses' => 'SlugController@slug']);

How to define this with laravel is it even possible ?

2 Answers 2

9

Possibly

Route::get('{slug}/{slugNum?}', 'SlugController@slug')->where('slugNum', '(.*)');

And in your controller you will need to just seperate the slugNum into an array (explode)

public function getPage($slug, $slugNum = null)
    {
        if($slugNum) 
        {
            $slugNum = explode('/', $slugNum);
            // all your slugs here.. to play with
        }
    }

I know this will work on 4!

0
Route::get('/slug/{slugNum}', [
//rest of the route
]);

Since, slugnum is our parameter, you can assign it from the origin it self or dynamically call the routes, multiple times as per the input.If you want to pass an array of parameters, use explode() (As seen above). Either way, it will work.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.