Sufyan
Sufyan

Reputation: 516

How to handle dashes route in laravel 5 for multiple parameter

This is my url structure

http://example.com/embed-id-size

http://example.com/embed-adsdfwer3-640x240

where size is optional parameter.

I coded in routes.php of laravel 5 like this.

Route::any('embed-{id}-{size?}',['uses'=>'Example@video','as'=>'embed']);

Above all working well no problem but problem comes when my id have already dash like this adsdfw-r3

http://example.com/embed-adsdfw-r3-640x240 http://example.com/embed-adsdfw-r3

above both url laravel route not working and route suppose there is three parameter.

And after many searches i found this ->where('id', '.*(?=-)') i apply this to my route and its working good only when i give size to my url but size is an optional parameter after applying ->where('id', '.*(?=-)') size becomes compulsory to give.

please help me how to solve this problem.

i hope u will understand my question.

Upvotes: 2

Views: 1371

Answers (1)

Angel Iliikov
Angel Iliikov

Reputation: 694

You have no easy way to solve that actually, because of the dash in the id.

I would either make sure there is no dash or I would capture the whole thing {id}-{size?} and calculate later if there is a resolution in the end or not and which one is the id.

Upvotes: 1

Related Questions