Reputation: 2853
I am trying to make a cookie but the team name I am getting from my database contains a space and it gives me this error : 'The cookie name "Czech Republic" contains invalid characters.'
and this is what I see in my url : http://localhost:8000/myteam/Czech%20Republic
The code from my view where I acces the route :
@foreach($teams as $teamitem)
<a href="{{URL::route('storeTeamCookie', $teamitem->name)}}">
</a>
@endforeach
The code in my controller:
public function storeCookie($team)
{
$cookie = Cookie::make($team, $team, 3600);
}
The code in my routes.php file :
Route::get('/myteam/{team}', array('as' => 'storeTeamCookie', 'uses' => 'MyteamController@storeCookie'));
Upvotes: 1
Views: 793
Reputation: 2853
I fixed it with the str_replace() method
code in controller :
public function storeCookie($team)
{
$team = str_replace(' ', '', $team);
Cookie::queue(Cookie::make($team, $team, 3600));
return View::make('myteam')->with('teams', $teams);
}
Upvotes: 0
Reputation: 13325
User urlencode
and urldecode
on the name when setting and getting the cookie/
$cookie = Cookie::make(urldecode($team), $team, 3600);
Upvotes: 1