Sufyan
Sufyan

Reputation: 516

Control multiple parameter with dashes in url

I am using laravel 5.0 framework and I have a route like this:

www.example.com/title-size

Where size is an optional parameter

Route::any('embed-{title}-{size?}',['uses'=>'Posts@getData','as'=>'embed'])->where('title', '.*(?=-)');

Because my title contains dashes so it was ignoring my optional size parameter so I have researched and found this ->where('title', '.*(?=-)'); which is working good. Now the problem comes that I have to allways add size parameter. If no size parameter the route is not working so it gives me a 404.

Upvotes: 2

Views: 196

Answers (1)

Please use Middleware as helper for your route. This is a standard in Laravel 5 and will help you achieve what you are looking for. Take a look at the basic examples from the /app/Http/Middleware/

Upvotes: 1

Related Questions