by  -
Look At More

Saving Cookie and Redirecting Page

This first example is a form and does not use the AJAX API

Cookie:

PHP Code

function onSaveItemRedirect() {
$item_id = Input::get('item_id');
$cookie = Cookie::forever('saved_item', $item_id);
Session::forget('cookie');
Cookie::queue($cookie);
return Redirect::refresh();
}




This second example uses the AJAX API and updates the cookie after an ajax response.

Cookie:

PHP Code

function onSaveItemAjax() {
$item_id = Input::get('item_id');
$cookie = Cookie::forever('saved_item', $item_id);
return Response::json(['Success'])->withCookie($cookie);
}

function onUpdateCookiePartial() {
return true;
}