{"id":1464,"date":"2018-10-12T06:37:41","date_gmt":"2018-10-11T21:37:41","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=1464"},"modified":"2019-01-26T17:47:36","modified_gmt":"2019-01-26T08:47:36","slug":"%e9%81%b8%e3%81%b9%e3%82%8b%e5%85%a8%ef%bc%94%e7%a8%ae%e9%a1%9e%ef%bc%81laravel%e3%81%a7%e6%9c%80%e7%b5%82%e3%83%ad%e3%82%b0%e3%82%a4%e3%83%b3%ef%bc%86%e3%83%ad%e3%82%b0%e3%82%a2%e3%82%a6%e3%83%88","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=1464","title":{"rendered":"\u9078\u3079\u308b\u5168\uff14\u7a2e\u985e\uff01Laravel\u3067\u6700\u7d42\u30ed\u30b0\u30a4\u30f3\uff06\u30ed\u30b0\u30a2\u30a6\u30c8\u65e5\u6642\u3092\u4fdd\u5b58\uff08\u305f\u3063\u305f\uff14\u884c\u301c\u30a4\u30d9\u30f3\u30c8\u307e\u3067\uff09"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u308c\u306fLaravel\u306b\u9650\u3089\u305a\u3069\u3093\u306a\u958b\u767a\u3067\u3082\u305d\u3046\u306a\u306e\u3067\u3059\u304c\u3001\u3042\u308b\u6a5f\u80fd\u3092\u5b9f\u88c5\u3059\u308b\u5834\u5408\u3001\u6761\u4ef6\u306b\u3088\u3063\u3066\u306f\u5168\u304f\u9055\u3063\u305f\u30a2\u30d7\u30ed\u30fc\u30c1\u3092\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u30c1\u30fc\u30e0\u5236\u306e\u5834\u5408\u3060\u3068\u3088\u308a\u4ed6\u306e\u4eba\u304c\u5206\u304b\u308a\u3084\u3059\u3044\u69cb\u9020\u3092\u610f\u8b58\u3057\u3066\u958b\u767a\u3092\u9032\u3081\u3066\u3044\u304f\u3079\u304d\u3067\u3059\u3057\u3001\u5358\u306b\u500b\u4eba\u7684\u306a\u30b5\u30a4\u30c8\u306a\u3089\u4e00\u756a\u30b7\u30f3\u30d7\u30eb\u306a\u65b9\u6cd5\u3067\u3082\u554f\u984c\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u4eca\u56de\u306e\u8a71\u984c\u3068\u3057\u3066\u9078\u3093\u3060\u300c\u6700\u7d42\u30ed\u30b0\u30a4\u30f3\u306e\u4fdd\u5b58\u300d\u306b\u95a2\u3057\u3066\u3082\u3053\u306e\u4f8b\u306b\u3082\u308c\u305a\u3001\u69d8\u3005\u306a\u30d1\u30bf\u30fc\u30f3\u306e\u30a2\u30d7\u30ed\u30fc\u30c1\u304c\u3042\u308b\u306e\u3067\u3001\u305b\u3063\u304b\u304f\u306a\u306e\u3067\u601d\u3044\u3064\u3044\u305f\u5168\u3066\u306e\u65b9\u6cd5\u3092\u307e\u3068\u3081\u3066\u516c\u958b\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305c\u3072\u5b66\u7fd2\u8005\u3055\u3093\u305f\u3061\u3082\u542b\u3081\u3066\u53c2\u8003\u306b\u306a\u308c\u3070\u5e78\u3044\u3067\u3059\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-418 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/35.png\" alt=\"\" width=\"370\" height=\"240\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/35.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/35-300x195.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<p>\u203b \u958b\u767a\u74b0\u5883\u306f\u3001Laravel 5.7\uff0bPHP 7\u3067\u3059\u3002<\/p>\n<h1>\u30e6\u30fc\u30b6\u30fc\u30c6\u30fc\u30d6\u30eb\u306e\u6e96\u5099<\/h1>\n<p>\u203b \u524d\u63d0\u3068\u3057\u3066Laravel\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u6709\u52b9\u306b\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002\u3084\u308a\u65b9\u306f\u3001<a href=\"https:\/\/blog.capilano-fw.com\/?p=289\">\u3010Laravel5.6\u3011\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u76f4\u5f8c\u306b\u3084\u308b\u3053\u3068\uff13\u70b9<\/a>\u306e\u300c<strong>\u30ed\u30b0\u30a4\u30f3\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u30ea\u30de\u30a4\u30f3\u30c0\u30fc\u6a5f\u80fd\u3092\u69cb\u7bc9<\/strong>\u300d\u3067\u8aac\u660e\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u307e\u305a\u6700\u5f8c\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u305f\u3081\u306e<code>last_login_at<\/code>\u30d5\u30a3\u30fc\u30eb\u30c9\u3092<code>User<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u8ffd\u52a0\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u5f8c\u304b\u3089\u8ffd\u52a0\u3059\u308b\u5f62\u5f0f\u3067\u3082\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u3088\u308a\u30b7\u30f3\u30d7\u30eb\u306b\u3044\u304d\u305f\u3044\u306e\u3067\u3001\u3059\u3067\u306b\u3042\u308b<code>database\/migrations\/2014_10_12_000000_create_users_table.php<\/code>\u3092\u958b\u3044\u3066\u76f4\u63a5\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<pre>public function up()\r\n{\r\n    Schema::create('users', function (Blueprint $table) {\r\n        $table-&gt;increments('id');\r\n        $table-&gt;string('name');\r\n        $table-&gt;string('email')-&gt;unique();\r\n        $table-&gt;string('password');\r\n        <strong>$table-&gt;dateTime('last_login_at')-&gt;nullable();<\/strong> \/\/ \u2190\u8ffd\u52a0\u3002null\u3082OK\u3002\r\n        $table-&gt;rememberToken();\r\n        $table-&gt;timestamps();\r\n    });\r\n}<\/pre>\n<p>\u3067\u306f\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u59cb\u3081\u304b\u3089\u3084\u308a\u76f4\u3059\u305f\u3081\u306b\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>php artisan migrate:fresh<\/strong><\/pre>\n<p>\u203b \u3082\u3057Seeder\u3092\u7528\u610f\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u4e00\u7dd2\u306b\u5b9f\u884c\u3059\u308b\u5834\u5408\u306f<code>--seed<\/code>\u3082\u3064\u3051\u3066\u5b9f\u884c\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre>php artisan migrate:fresh <strong>--seed<\/strong><\/pre>\n<p>\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068DB\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1465\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/users_last_login_field.png\" alt=\"\" width=\"341\" height=\"314\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/users_last_login_field.png 341w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/users_last_login_field-300x276.png 300w\" sizes=\"auto, (max-width: 341px) 100vw, 341px\" \/><\/p>\n<p>\u3067\u306f\u3001\u6b21\u304b\u3089\u5b9f\u969b\u306b\u6700\u7d42\u30ed\u30b0\u30a4\u30f3\u65e5\u6642\u3092\u4fdd\u5b58\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h1>\u6700\u7d42\u30ed\u30b0\u30a4\u30f3\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u65b9\u6cd5<\/h1>\n<h2>\u305f\u3063\u305f\uff14\u884c\u3067\u5b9f\u88c5\u3059\u308b\u4e00\u756a\u30b7\u30f3\u30d7\u30eb\u306a\u65b9\u6cd5<\/h2>\n<p>Laravel\u306e\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u6709\u52b9\u306b\u3059\u308b\u3068\u3001<code>app\/Http\/Controllers\/Auth<\/code>\u3068\u3044\u3046\u30d5\u30a9\u30eb\u30c0\u304c\u4f5c\u6210\u3055\u308c\u3001\u3053\u306e\u4e2d\u306b\u30ed\u30b0\u30a4\u30f3\u5168\u822c\u306b\u95a2\u9023\u3059\u308b\u4ee5\u4e0b\uff15\u3064\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u304c\u4f5c\u6210\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>ForgetPasswordController<\/li>\n<li>LoginController<\/li>\n<li>RegisterController<\/li>\n<li>ResetPasswordController<\/li>\n<li>VerificationController<\/li>\n<\/ul>\n<p>\u305d\u3057\u3066\u3001\u30ed\u30b0\u30a4\u30f3\u6642\u306e\u7ba1\u7406\u3092\u3059\u308b\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc<code>LoginController.php<\/code>\u306e\u4e2d\u306b<code>authenticated()<\/code>\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3060\u3051\u3067\u6700\u7d42\u30ed\u30b0\u30a4\u30f3\u6642\u9593\u306e\u4fdd\u5b58\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>protected function authenticated(Request $request, $user)<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    $user-&gt;last_login_at = now();<\/strong>\r\n<strong>    $user-&gt;save();<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>\u203b <code>authenticated()<\/code>\u306f<code>AuthenticatesUsers<\/code>\u3068\u3044\u3046\u30c8\u30ec\u30a4\u30c8\u306e\u4e2d\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u30e1\u30bd\u30c3\u30c9\u306a\u306e\u3067\u3001\u521d\u671f\u72b6\u614b\u3067\u306f<code>LoginController.php<\/code>\u306b\u306f\u8a18\u8ff0\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<p>\u306a\u304a\u3001\u5f15\u6570\u306e<code>Request<\/code>\u306f\u30cd\u30fc\u30e0\u30b9\u30da\u30fc\u30b9\u304c\u5fc5\u8981\u306a\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<pre><strong>use Illuminate\\Http\\Request;<\/strong><\/pre>\n<p>\u3053\u306e\u65b9\u6cd5\u306f\u3068\u3066\u3082\u30b7\u30f3\u30d7\u30eb\u306a\u306e\u3067\u3001\u4fdd\u5b88\u7ba1\u7406\u306b\u305d\u308c\u307b\u3069\u3053\u3060\u308f\u308b\u5fc5\u8981\u304c\u306a\u3044\u5c0f\u898f\u6a21\u306a\u30b5\u30a4\u30c8\u306b\u5411\u3044\u3066\u3044\u308b\u3068\u3044\u3048\u307e\u3059\u3002<\/p>\n<h2>\u30ed\u30b0\u30a4\u30f3\u30fb\u30a4\u30d9\u30f3\u30c8\u3067\u5b9f\u88c5\u3059\u308b<\/h2>\n<p>\u5148\u307b\u3069\u306e\u65b9\u6cd5\u306f\u305f\u3063\u305f\uff14\u884c\u3067\u66f8\u3051\u308b\u306e\u3067\u3068\u3066\u3082\u30b7\u30f3\u30d7\u30eb\u3067\u3059\u304c\u3001<code>authenticated()<\/code>\u306e\u5b58\u5728\u3092\u77e5\u3089\u306a\u3044\u4eba\u9593\u304b\u3089\u3059\u308b\u3068\u76f4\u611f\u7684\u306b\u3053\u3053\u3092\u898b\u3064\u3051\u308b\u306e\u306f\u96e3\u3057\u304f\u3001\u30c1\u30fc\u30e0\u3067\u958b\u767a\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u30d9\u30bf\u30fc\u306a\u65b9\u6cd5\u3068\u306f\u8a00\u3048\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u307e\u305f\u3001\u6700\u7d42\u30ed\u30b0\u30a4\u30f3\u60c5\u5831\u3060\u3051\u3067\u306a\u304fIP\u30a2\u30c9\u30ec\u30b9\u7b49\u3055\u307e\u3056\u307e\u306a\u60c5\u5831\u3092\u4fdd\u5b58\u3059\u308b\u306a\u3069\u3001\u4ed8\u968f\u3059\u308b\u30b3\u30fc\u30c9\u304c\u591a\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u5834\u5408\u306f\u3001\u5c02\u7528\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u3063\u3066\u30ab\u30d7\u30bb\u30eb\u5316\u3057\u3001\u3088\u308a\u4fdd\u5b88\u7ba1\u7406\u3092\u3057\u3084\u3059\u304f\u3057\u3066\u304a\u304f\u3079\u304d\u3067\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\uff12\u3064\u76ee\u306f\u30ed\u30b0\u30a4\u30f3\u30fb\u30a4\u30d9\u30f3\u30c8\u3092\u4f7f\u3063\u3066\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f<code>app\/Providers\/EventServiceProvider.php<\/code>\u3092\u958b\u3044\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30ed\u30b0\u30a4\u30f3\u6210\u529f\u30a4\u30d9\u30f3\u30c8\u3092\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<pre>protected $listen = [\r\n    \/\/ \u30ed\u30b0\u30a4\u30f3\u6210\u529f\u3057\u305f\u3089\u5b9f\u884c\r\n<strong>    'Illuminate\\Auth\\Events\\Authenticated' =&gt; [<\/strong>\r\n<strong>        'App\\Listeners\\LogAuthenticated',<\/strong>\r\n<strong>    ],<\/strong>\r\n\r\n    \/\/ \u7701\u7565<\/pre>\n<p>\u305f\u3060\u3057\u3001\u3053\u306e\u72b6\u614b\u3067\u306f\u307e\u3060\u8d77\u52d5\u3059\u308b\u30a4\u30d9\u30f3\u30c8\u30fb\u30ea\u30b9\u30ca\u30fc\u304c\u5b58\u5728\u3057\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u81ea\u52d5\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>php artisan event:generate<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001<code>app\/Listeners\/LogAuthenticated.php<\/code>\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066<code>handle()<\/code>\u5185\u306b\u6700\u7d42\u30ed\u30b0\u30a4\u30f3\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>public function handle($event)<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    $event-&gt;user-&gt;last_login_at = now();<\/strong>\r\n<strong>    $event-&gt;user-&gt;save();<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<p><strong>\u3010\u8ffd\u8a18\uff1a2019.01.26\u3011<\/strong><code>LogAuthenticated<\/code>\u306f\u3001\u30ed\u30b0\u30a4\u30f3\u4e2d\u306b\u30da\u30fc\u30b8\u79fb\u52d5\u304c\u3042\u3063\u305f\u5834\u5408\u306b\u6bce\u56de\u547c\u3070\u308c\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u30ed\u30b0\u30a4\u30f3\u6642\u306e\u307f\u30c7\u30fc\u30bf\u66f4\u65b0\u3057\u305f\u3044\u5834\u5408\u306f<code>LoginController.php<\/code>\u3092\u4f7f\u3046\u65b9\u6cd5\u3067\u5b9f\u88c5\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u6700\u7d42\u30ed\u30b0\u30a2\u30a6\u30c8\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u65b9\u6cd5<\/h1>\n<p>\u30ed\u30b0\u30a4\u30f3\u60c5\u5831\u3092\u4fdd\u5b58\u3059\u308b\u5834\u5408\u3068\u5c11\u3057\u9055\u3063\u3066\u3044\u308b\u90e8\u5206\u304c\u3042\u308b\u306e\u3067\u3001\u3053\u3061\u3089\u3082\uff12\u3064\u306e\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u30ed\u30b0\u30a4\u30f3\u6642\u3068\u540c\u3058\u304f\u30c6\u30fc\u30d6\u30eb\u306b<code>last_logout_at<\/code>\u3068\u3044\u3046\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre>Schema::create('users', function (Blueprint $table) {\r\n    $table-&gt;increments('id');\r\n    $table-&gt;string('name');\r\n    $table-&gt;string('email')-&gt;unique();\r\n    $table-&gt;string('password');\r\n    $table-&gt;dateTime('last_login_at')-&gt;nullable();\r\n    <strong>$table-&gt;dateTime('last_logout_at')-&gt;nullable(); \/\/ \u2190\u8ffd\u52a0<\/strong>\r\n    $table-&gt;rememberToken();\r\n    $table-&gt;timestamps();\r\n});<\/pre>\n<pre><strong>php artisan migrate:fresh --seed<\/strong><\/pre>\n<p>\u30c6\u30fc\u30d6\u30eb\u69cb\u9020\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1467\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/users_last_logout_field.png\" alt=\"\" width=\"343\" height=\"337\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/users_last_logout_field.png 343w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/users_last_logout_field-300x295.png 300w\" sizes=\"auto, (max-width: 343px) 100vw, 343px\" \/><\/p>\n<h2>LoginController\u3067\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5<\/h2>\n<p>\u6700\u7d42\u30ed\u30b0\u30a4\u30f3\u4fdd\u5b58\u306e\u3068\u304d\u3068\u540c\u3058\u304f<code>LoginController.php<\/code>\u306e\u4e2d\u3067<code>logout()<\/code>\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u307e\u3059\u304c\u3001\u5c11\u3057\u30a2\u30d7\u30ed\u30fc\u30c1\u304c\u7570\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u305c\u306a\u3089\u3001\u30c8\u30ec\u30a4\u30c8\u306f\u540c\u3058\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u3063\u3066\u3057\u307e\u3046\u3068\u4e0a\u66f8\u304d\u3055\u308c\u3066\u6d88\u6ec5\u3057\u3066\u3057\u307e\u3046\u305f\u3081\u3001<code>logout()<\/code>\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066\u3057\u307e\u3046\u3068\u3001\u672c\u6765\u5fc5\u8981\u306a\u30ed\u30b0\u30a2\u30a6\u30c8\u306e\u624b\u9806\u304c\u5b9f\u884c\u3055\u308c\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u305f\u3081\u3067\u3059\u3002<\/p>\n<p>\u304b\u3068\u8a00\u3063\u3066<code>loggedOut()<\/code>\u3092\u4f7f\u3063\u3066\u3082\u3001\u3053\u3061\u3089\u306f\u30ed\u30b0\u30a2\u30a6\u30c8\u5f8c\u306a\u306e\u3067\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u5f15\u304d\u51fa\u3059\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u3082\u3061\u308d\u3093\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>AuthenticatesUsers<\/code>\u306e<code>logout()<\/code>\u5185\u306e\u8a18\u8ff0\u3092\u305d\u3063\u304f\u308a\u305d\u306e\u307e\u307e\u30b3\u30d4\u30fc\u3057\u3066\u5fc5\u8981\u306a\u30b3\u30fc\u30c9\u3092\u8db3\u3059\u3068\u3044\u3046\u65b9\u6cd5\u3082\u7121\u304f\u306f\u306a\u3044\u3067\u3059\u304c\u3001\u4eca\u5f8cLaravel\u304c\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3055\u308c\u305f\u5834\u5408\u306b\u8a18\u8ff0\u304c\u5909\u308f\u3063\u3066\u3057\u307e\u3046\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u3053\u308c\u3082\u3042\u307e\u308a\u304a\u3059\u3059\u3081\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<pre>public function logout(Request $request)\r\n{\r\n    \/\/ \u3053\u3053\u306b\u30b3\u30fc\u30c9\u3092\u8db3\u3059\uff08\u304a\u3059\u3059\u3081\u3057\u306a\u3044\u65b9\u6cd5\u3067\u3059\uff01\uff09\r\n\r\n    $this-&gt;guard()-&gt;logout();\r\n\r\n    $request-&gt;session()-&gt;invalidate();\r\n\r\n    return $this-&gt;loggedOut($request) ?: redirect('\/');\r\n}<\/pre>\n<p>\u3067\u306f\u3053\u308c\u3092\u89e3\u6c7a\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308b\u304b\u3068\u3044\u3046\u3068\u3001<code>as<\/code>\u3092\u4f7f\u3063\u3066\u540d\u524d\u3092\u5909\u66f4\u3059\u308c\u3070OK\u3067\u3059\u3002\u5b9f\u969b\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>class LoginController extends Controller\r\n{\r\n    <strong>use AuthenticatesUsers { logout as originalLogout; }<\/strong>\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    public function logout(Request $request)\r\n    {\r\n        $user = $request-&gt;user();\r\n        $user-&gt;last_logout_at = now();\r\n        $user-&gt;save();\r\n\r\n        return <strong>$this-&gt;originalLogout($request); \/\/ \u5143\u3005\u306e\u30ed\u30b0\u30a2\u30a6\u30c8<\/strong>\r\n    }\r\n\r\n}<\/pre>\n<p>\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u3001\u3082\u3068\u3082\u3068\u306e<code>logout()<\/code>\u30e1\u30bd\u30c3\u30c9\u306e\u540d\u524d\u3092<code>originalLogout()<\/code>\u306b\u5909\u66f4\u3057\u3001\u65b0\u3057\u304f\u8ffd\u52a0\u3057\u305f<code>logout()<\/code>\u5185\u3067\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u672c\u6765\u306e\u30ed\u30b0\u30a2\u30a6\u30c8\u51e6\u7406\u3092\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u3082\u3061\u308d\u3093\u65b0<code>logout()<\/code>\u306e\u4e2d\u3067\u306f\u3001\u30ed\u30b0\u30a2\u30a6\u30c8\u76f4\u524d\u306b\u6700\u7d42\u30ed\u30b0\u30a2\u30a6\u30c8\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30ed\u30b0\u30a2\u30a6\u30c8\u30fb\u30a4\u30d9\u30f3\u30c8\u3067\u5b9f\u88c5\u3059\u308b<\/h2>\n<p>\u30a4\u30d9\u30f3\u30c8\u3092\u4f7f\u3063\u3066\u6700\u7d42\u30ed\u30b0\u30a2\u30a6\u30c8\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u306b\u306f\u3001\u30ed\u30b0\u30a4\u30f3\u306e\u5834\u5408\u3068\u540c\u3058\u304f\u30a4\u30d9\u30f3\u30c8\u306e\u767b\u9332\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><code>app\/Providers\/EventServiceProvider.php<\/code>\u3092\u958b\u3044\u3066\u30ed\u30b0\u30a2\u30a6\u30c8\u30fb\u30a4\u30d9\u30f3\u30c8\u3092\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<pre>protected $listen = [\r\n    \/\/ \u30ed\u30b0\u30a2\u30a6\u30c8\u304c\u6210\u529f\u3057\u305f\u3089\u5b9f\u884c\r\n<strong>    'Illuminate\\Auth\\Events\\Logout' =&gt; [<\/strong>\r\n<strong>        'App\\Listeners\\LogSuccessfulLogout',<\/strong>\r\n<strong>    ],<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30a4\u30d9\u30f3\u30c8\u30fb\u30ea\u30b9\u30ca\u30fc<code>LogSuccessfulLogout<\/code>\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan event:generate<\/strong><\/pre>\n<p>\u6700\u5f8c\u306b\u3001\u4f5c\u6210\u3057\u305f<code>app\/Listeners\/LogSuccessfullLogout.php<\/code>\u306e<code>handle()<\/code>\u5185\u3067\u540c\u3058\u304f\u30ed\u30b0\u30a2\u30a6\u30c8\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u8a18\u8ff0\u3092\u3059\u308c\u3070OK\u3067\u3059\u3002<\/p>\n<pre><strong>public function handle(Logout $event)<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    $event-&gt;user-&gt;last_logout_at = now();<\/strong>\r\n<strong>    $event-&gt;user-&gt;save();<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>\u203b \u3061\u306a\u307f\u306b\u3001<code>LogSuccessfulLogout<\/code>\u30a4\u30d9\u30f3\u30c8\u306f\u5b9f\u969b\u306b\u30ed\u30b0\u30a2\u30a6\u30c8\u3057\u305f\u5f8c\u3067\u3082\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u306f\u6b8b\u3057\u3066\u304f\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306b\u4fdd\u5b58\u304c\u53ef\u80fd\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h1>\u4eca\u56de\u4f7f\u3063\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/h1>\n<p>\u4ee5\u4e0b\u304b\u3089\u3001\u4eca\u56de\u306e\u8a18\u4e8b\u3067\u5b9f\u969b\u306b\u4f7f\u3063\u305f<code>LoginController<\/code>\u3001<code>LogAuthenticated<\/code>\u3001<code>LogSuccessfulLogout<\/code>\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u203b \u305f\u3060\u3057\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3084\u30a4\u30d9\u30f3\u30c8\u306e\u767b\u9332\u306f\u3053\u306e\u8a18\u4e8b\u3092\u53c2\u8003\u306b\u3057\u3066\u3054\u81ea\u8eab\u3067\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u5168\u3066\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5b9f\u88c5\u3059\u308b\u3068\u4e8c\u91cd\u3067\u30ed\u30b0\u30a4\u30f3\uff06\u30ed\u30b0\u30a2\u30a6\u30c8\u60c5\u5831\u304c\u4fdd\u5b58\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u3053\u3061\u3089\u3082\u3069\u3061\u3089\u304b\u3054\u81ea\u8eab\u3067\u9078\u629e\u3057\u3066\u5b9f\u88c5\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=1476&amp;tmstv=1777540942\" rel=\"nofollow\" id=\"download-link-1476\" data-redirect=\"false\" >\n\t\u6700\u7d42\u30ed\u30b0\u30a4\u30f3\uff06\u30ed\u30b0\u30a2\u30a6\u30c8\u65e5\u6642\u3092\u4fdd\u5b58\u3059\u308b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/a>\n\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u308c\u306fLaravel\u306b\u9650\u3089\u305a\u3069\u3093\u306a\u958b\u767a\u3067\u3082\u305d\u3046\u306a\u306e\u3067\u3059\u304c\u3001\u3042\u308b\u6a5f\u80fd\u3092\u5b9f\u88c5\u3059\u308b\u5834\u5408\u3001\u6761\u4ef6\u306b\u3088\u3063\u3066\u306f\u5168\u304f\u9055\u3063\u305f\u30a2\u30d7\u30ed\u30fc\u30c1\u3092\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002 \u4f8b\u3048\u3070\u3001\u30c1 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=1464\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u9078\u3079\u308b\u5168\uff14\u7a2e\u985e\uff01Laravel\u3067\u6700\u7d42\u30ed\u30b0\u30a4\u30f3\uff06\u30ed\u30b0\u30a2\u30a6\u30c8\u65e5\u6642\u3092\u4fdd\u5b58\uff08\u305f\u3063\u305f\uff14\u884c\u301c\u30a4\u30d9\u30f3\u30c8\u307e\u3067\uff09&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":1481,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,97],"tags":[92,58],"class_list":["post-1464","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","category-97","tag-92","tag-58"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/1464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1464"}],"version-history":[{"count":14,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/1464\/revisions"}],"predecessor-version":[{"id":3293,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/1464\/revisions\/3293"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/1481"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}