こんなにもシンプルなSESSIONが追加できない
app/Http/Controllers/HogeController.php
public function show()
{
if (!Session::has('token')) {
Session::put('token', 'token!');
var_dump('saved!');
}
var_dump(Session::get('token'));
return view('welcome');
}
初回のみ「saved!token!」と表示され、2回目以降は「token!」となってほしい。
しかし、何度試しても「saved!token!」が表示される。
不用意にダンプしたらダメなんだってさ
https://laracasts.com/discuss/channels/laravel/sessions-are-not-saving?page=1
sessions work fine, but only if your code exits normally and runs the terminable middleware. If you dd() in your code then the session is not saved
https://laravel.com/docs/5.5/middleware#terminable-middleware
you should also run php artisan route:list and check that you have web against each route, once only per route
テストコードのvar_dumpを削除したらセッションにちゃんと保存できた。
app/Http/Controllers/HogeController.php
public function show()
{
if (!Session::has('token')) {
Session::put('token', ’token!’);
}
return view('welcome');
}