php - Laravel 5, have full url as a route parameter -
i need pass full url route parameter on laravel 5 application, thing follows. i'm creating thumbnail service having url of original photo resizes , streams browser. example, need img source have src this:
<img src="http://host.com/generate-thumb/300x300/http://host.com/images/media1.png"/>
so in controller can original image url this:
public function thumbaction(request $request, $size, $original_url){ dd($size, $original_url); }
and route definition follows:
route::get('/generate-thumb/{size}/{original_url}', array( 'as' => 'thumb_hook', 'uses' => 'thumbcontroller@thumbaction' ));
i have done way server responds 404 error.
i have specified url pattern in where
method of route definition.
does knows how that?
the issue you're running url parameters are, default, delimited forward slashes (/
). since 1 of parameters contain forward slashes, run special situation.
given current route definition, , given url http://host.com/generate-thumb/300x300/http://host.com/images/media1.png
, happens size
parameter gets 300x300
, original_url
parameter gets http:
, , there bunch more parameters. since don't have route defined this, 404.
in order allow parameter accept forward slashes, need define regex constraint parameter. need define route this:
route::get('/generate-thumb/{size}/{original_url}', array( 'as' => 'thumb_hook', 'uses' => 'thumbcontroller@thumbaction' )) ->where('original_url', '.*');
this .*
constraint allow parameter accept character, including forward slashes. note when this, parameter need last defined parameter, since eats forward slashes , won't able delimit other route parameters.
Comments
Post a Comment