First of all lets discuss many ways to set cookies inside controller :
To get cookies: inside controller
in blade:
{{ Cookie::get('news_id') }}
Now lets see for session:
Ref: https://laracasts.com/discuss/channels/eloquent/how-to-set-a-session-variable?page=1
https://stackoverflow.com/questions/37292167/php-laravel-how-to-set-or-get-session-data
https://laravel.com/docs/5.8/session
https://www.tutorialspoint.com/laravel/laravel_session.htm
$response = new Response(redirect('news'));
//$minute=5;
// $response->withCookie(cookie('name', 'virat', $minutes));
$response->withCookie(cookie()->forever('news_id', $newsid));
return $response;
// or
// Cookie::queue('news_id', $news_id, 15);
// return redirect('news');
// or
// return redirect('news')->withCookie(cookie('name', 'virat', $minutes));
use Illuminate\Support\Facades\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Cookie;
To get cookies: inside controller
$val=Request::cookie('news_id');
// dd($val);
$v=Cookie::get('news_id');
// dd($v);
or $value = $request->cookie('name');
in blade:
{{ Cookie::get('news_id') }}
Now lets see for session:
Ref: https://laracasts.com/discuss/channels/eloquent/how-to-set-a-session-variable?page=1
https://stackoverflow.com/questions/37292167/php-laravel-how-to-set-or-get-session-data
https://laravel.com/docs/5.8/session
https://www.tutorialspoint.com/laravel/laravel_session.htm
Comments
Post a Comment