php - Laravel 4.2 link to action links & as %27 -
hello have following line:
{{ link_to_action('friendcontroller@add', 'friend ' .explode(" ", $user->name)[0],[auth::user()->id,$user->id]) }} and route defined as
route::post('friend/add{id}&{fid}', ['as' => 'friend.add', 'uses' => 'friendcontroller@add']); however url isn't parsing 2 arguments correctly comes /add1%262 instead of /add?1&2
i cant figure out why, working before. comes method [show] not exist when go through.
there 2 problems here, fail match expectations supposed happen:
1. first , importat one, link_to_action helper function uses to method in illuminate\routing\urlgenerator class generate url, in turn makes use of rawurlencode method encode reserved characters according rfc 3986. since & character reserved sub-delimiter character automatically encoded %26, result in url path looking /add1%262.
2. second issue define route path friend/add{id}&{fid}, yet expect have ? in there. if add route definition friend/add?{id}&{fid}, still not work because ? delimiter character , encoded well, you'll end /add%3f1%262.
the central issue here should not defining query string parameters in laravel route definition. either move parameters route definition query string , build html link , url manually:
// routes.php route::post('friend/add', ['as' => 'friend.add', 'uses' => 'friendcontroller@add']); // blade template <a href="{{ action('friendcontroller@add') }}?{{ auth::user()->id }}&{{ $user->id }}"> friend {{ explode(" ", $user->name)[0] }} </a> or change route definition doesn't contain reserved characters might encoded:
// routes.php route::post('friend/add/{id}/{fid}', ['as' => 'friend.add', 'uses' => 'friendcontroller@add']); // blade template {{ link_to_action('friendcontroller@add', 'friend ' .explode(" ", $user->name)[0],[auth::user()->id,$user->id]) }} that being said, current setup generates path /add1%262, laravel still know decode parameters, in controller action method you'll still 1 , 2 user ids:
public function add($id, $fid) { // $id = 1 // $fid = 2 }
Comments
Post a Comment