20
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

laravel session と cookie の 使い方

Posted at

#Session 使おうぜ

・Controllerでもviewでもどこでも使える。
・空のセッションが読み込まれてもエラーにならない。
・もちろんページ移動しても使える。


//書き込み
session(['kudamono' => 'ringo']);

//読み出し
session('kudamono')
//読み出し (view)
{{session('kudamono')}}

//削除
session()->forget('kudamono');

#Cookie 使おうぜ

・書き込み時は、次回アクセスした時から設定したCookieが有効となる。
・削除時はlaravelの機能を使わない。


//書き込み (100分)
\Cookie::queue('testcookie', "たろまん",100);

//取得
$test = \Cookie::get('testcookie');
//viewで取得
{{\Cookie::get('testcookie')}}

//削除
setcookie('testcookie');


以上

20
16
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?