{"id":2889,"date":"2018-12-15T03:44:30","date_gmt":"2018-12-14T18:44:30","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=2889"},"modified":"2019-01-26T19:28:17","modified_gmt":"2019-01-26T10:28:17","slug":"%e3%83%ad%e3%82%b0%e3%82%a4%e3%83%b3%e4%b8%ad%e3%81%aelaravel%e3%83%a6%e3%83%bc%e3%82%b6%e3%83%bc%e3%81%a7wordpress%e3%81%b8%e8%87%aa%e5%8b%95%e3%83%ad%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=2889","title":{"rendered":"\u30ed\u30b0\u30a4\u30f3\u4e2d\u306eLaravel\u30e6\u30fc\u30b6\u30fc\u3067wordpress\u3078\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u3059\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u524d\u56de\u00a0<a href=\"https:\/\/blog.capilano-fw.com\/?p=2867\" target=\"_blank\" rel=\"noopener\">Laravel\u306e\u30e6\u30fc\u30b6\u30fc\u3067wordpress\u3078\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b<\/a> \u3067\u306f\u3001<code>Laravel<\/code>\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u4f7f\u3063\u3066<code>wordpress<\/code>\u3078\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306a\u4f7f\u3044\u65b9\u3092\u3059\u308b\u3053\u3068\u3067\u3001\u4f8b\u3048\u3070<code>Laravel<\/code>\u3067\u958b\u767a\u3055\u308c\u305f\u30b5\u30a4\u30c8\u3067\u3042\u3063\u3066\u3082\u5404\u30e6\u30fc\u30b6\u30fc\u304c<code>wordpress<\/code>\u3067\u958b\u8a2d\u3055\u308c\u305f\u5171\u540c\u30d6\u30ed\u30b0\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3001\u30e6\u30fc\u30b6\u30fc\u5168\u54e1\u3067\u60c5\u5831\u767a\u4fe1\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3053\u306e\u5834\u5408\u3001\u3072\u3068\u3064\u3042\u308b\u8ab2\u984c\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u306f\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u3059\u3067\u306b<code>Laravel<\/code>\u306e\u30b5\u30a4\u30c8\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u306e\u306b\u3001\u518d\u5ea6\u30d6\u30ed\u30b0\u30da\u30fc\u30b8\u3067\u30ed\u30b0\u30a4\u30f3\u3092\u8981\u6c42\u3055\u308c\u308b\u3001\u3064\u307e\u308a\u30e6\u30fc\u30b6\u30d3\u30ea\u30c6\u30a3\u304c\u3042\u307e\u308a\u826f\u304f\u306a\u3044\u72b6\u6cc1\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\uff01<\/p>\n<p>\u4eca\u56de\u306f\u72ec\u81ea\u30d7\u30e9\u30b0\u30a4\u30f3<code>laravel-auto-login<\/code>\u3092\u4f5c\u6210\u3057\u3066\u3001\u3059\u3067\u306b<code>Laravel<\/code>\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u81ea\u52d5\u7684\u306b<code>wordpress<\/code>\u306b\u30ed\u30b0\u30a4\u30f3\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1785 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/15-2.png\" alt=\"\" width=\"226\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/15-2.png 226w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/15-2-212x300.png 212w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/><\/p>\n<p>\u203b \u958b\u767a\u74b0\u5883\uff1a Laravel 5.7\u3001wordpress 5.0<\/p>\n<h1>\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u306e\u624b\u9806<\/h1>\n<p>\u304a\u304a\u307e\u304b\u306b\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u306f\u6b21\u306e\u624b\u9806\u3067\u884c\u3044\u307e\u3059\u3002<\/p>\n<ol>\n<li>Laravel\u306e\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u304c\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u7528\u306e\u30c8\u30fc\u30af\u30f3\u3092\u4fdd\u6301\u3059\u308b<\/li>\n<li>wordpress\u3067\u305d\u306e\u30c8\u30fc\u30af\u30f3\u3092\u4f7f\u3063\u3066\u8a8d\u8a3c\u3092\u3059\u308b<\/li>\n<li>\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u3092\u5b9f\u884c\u3059\u308b<\/li>\n<\/ol>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u958b\u767a\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<h1>Laravel\u5074\u306e\u4f5c\u696d<\/h1>\n<h2>\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u7528\u30c8\u30fc\u30af\u30f3\u306e\u305f\u3081\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u8ffd\u52a0\u3059\u308b<\/h2>\n<p>\u307e\u305a\u306f<code>Laravel<\/code>\u306e\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u4fdd\u5b58\u3057\u3066\u3044\u308b\u30c6\u30fc\u30d6\u30eb\u306b<code>auto_login_token<\/code>\u3068\u3044\u3046\u540d\u524d\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3059\u3067\u306b\u3042\u308b\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3<code>database\/migrations\/****_**_**_******_create_users_table.php<\/code>\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;timestamp('email_verified_at')-&gt;nullable();\r\n        $table-&gt;string('password');\r\n        <strong>$table-&gt;string('auto_login_token')-&gt;nullable();<\/strong>\r\n        $table-&gt;rememberToken();\r\n        $table-&gt;timestamps();\r\n    });\r\n}<\/pre>\n<p>\u8a2d\u5b9a\u304c\u7d42\u308f\u3063\u305f\u3089\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u30c6\u30fc\u30d6\u30eb\u69cb\u9020\u306f\u3053\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2890\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_1.png\" alt=\"\" width=\"330\" height=\"332\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_1.png 330w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_1-150x150.png 150w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_1-298x300.png 298w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_1-100x100.png 100w\" sizes=\"auto, (max-width: 330px) 100vw, 330px\" \/><\/p>\n<h2>\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u30fb\u30c8\u30fc\u30af\u30f3\u306e\u30a4\u30d9\u30f3\u30c8\u3092\u4f5c\u6210\u3059\u308b<\/h2>\n<p>\u307e\u305a\u3001<code>auto_login_token<\/code>\u30d5\u30a3\u30fc\u30eb\u30c9\u306f\u3001\u6b21\u306e\u3088\u3046\u306a\u4f7f\u3044\u65b9\u3092\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u3089\u65b0\u3057\u3044\u6587\u5b57\u5217\u3092\u4fdd\u5b58<\/li>\n<li>\u30ed\u30b0\u30a2\u30a6\u30c8\u3057\u305f\u3089\u7a7a\u306b\u3059\u308b<\/li>\n<\/ul>\n<p>\u305d\u306e\u305f\u3081\u3001\u3053\u308c\u3089\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306b\u30ed\u30b0\u30a4\u30f3\uff06\u30ed\u30b0\u30a2\u30a6\u30c8\u6642\u306b\u5b9f\u884c\u3055\u308c\u308b\u30a4\u30d9\u30f3\u30c8\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f<code>app\/Providers\/EventServiceProvider.php<\/code>\u3092\u958b\u3044\u3066\u3001\u6b21\u306e\u3088\u3046\u306b\u30ed\u30b0\u30a4\u30f3\u3068\u30ed\u30b0\u30a2\u30a6\u30c8\u306b\u5b9f\u884c\u3055\u308c\u308b\u30a4\u30d9\u30f3\u30c8\u3092\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>\/\/ app\/Providers\/EventServiceProvider.php<\/strong>\r\n\r\nprotected $listen = [\r\n    <strong>'Illuminate\\Auth\\Events\\Authenticated' =&gt; [<\/strong>\r\n<strong>        'App\\Listeners\\LogAuthenticated',<\/strong>\r\n<strong>    ],<\/strong>\r\n<strong>    'Illuminate\\Auth\\Events\\Logout' =&gt; [<\/strong>\r\n<strong>        'App\\Listeners\\LogSuccessfulLogout',<\/strong>\r\n<strong>    ],<\/strong>\r\n    \r\n    \/\/ \u7701\u7565\r\n\r\n];<\/pre>\n<p>\u305d\u3057\u3066\u3001\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u30a4\u30d9\u30f3\u30c8\u30ea\u30b9\u30ca\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan event:generate<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001<code>app\/Listeners<\/code>\u30d5\u30a9\u30eb\u30c0\u306e\u4e2d\u306b\u4ee5\u4e0b\uff12\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u3053\u308c\u3089\uff12\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u5185\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u8fbc\u3093\u3067\u3044\u304d\u307e\u3059\u3002<\/p>\n<ul>\n<li>LogAuthenticated.php<\/li>\n<li>LogSuccessfulLogout.php<\/li>\n<\/ul>\n<p>\u203b \u306a\u304a\u3001\u30ed\u30b0\u30a4\u30f3\uff06\u30ed\u30b0\u30a2\u30a6\u30c8\u6642\u306e\u30a4\u30d9\u30f3\u30c8\u3092\u8a73\u3057\u304f\u77e5\u308a\u305f\u3044\u65b9\u306f\u3001<a href=\"https:\/\/blog.capilano-fw.com\/?p=1464\">\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<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>LogAuthenticated<\/h3>\n<p><s>\u30ed\u30b0\u30a4\u30f3\u304c\u6210\u529f\u3057\u305f\u3068\u304d\u306e\u30a4\u30d9\u30f3\u30c8<\/s>\u00a0\u8a8d\u8a3c\u304c\u6210\u529f\u3057\u305f\u3068\u304d\u306e\u30a4\u30d9\u30f3\u30c8\u3067\u3059\u306e\u3067\u3001\u6b21\u306e\u3088\u3046\u65b0\u3057\u3044<code>auto_login_token<\/code>\u3092\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<pre>public function handle(<strong>Authenticated $event<\/strong>)\r\n{\r\n    <strong>$user = $event-&gt;user;<\/strong>\r\n<strong>    $user-&gt;auto_login_token = $user-&gt;id .'-'. str_random(32);<\/strong>\r\n<strong>    $user-&gt;save();<\/strong>\r\n}<\/pre>\n<p>\u3053\u308c\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u3089\u5404\u30e6\u30fc\u30b6\u30fc\u306b\u4e00\u610f\u306a\u6587\u5b57\u5217\u304c\u4fdd\u5b58\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2891\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_2.png\" alt=\"\" width=\"279\" height=\"97\" \/><\/p>\n<p>\u203b \u3053\u306e\u65b9\u6cd5\u306f\u3001\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u30da\u30fc\u30b8\u79fb\u52d5\u3059\u308b\u3068\u6bce\u56de\u547c\u3070\u308c\u307e\u3059\u3002\u3082\u3057\u30ed\u30b0\u30a4\u30f3\u6642\u306b\uff11\u56de\u3060\u3051\u5b9f\u884c\u3057\u305f\u3044\u5834\u5408\u306f<code>LoginController.php<\/code>\u306e<code>authenticated()<\/code>\u3067\u5b9f\u88c5\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u8a73\u3057\u304f\u306f<a href=\"https:\/\/blog.capilano-fw.com\/?p=1464\">\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<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>LogSuccessfulLogout<\/h3>\n<p>\u30ed\u30b0\u30a2\u30a6\u30c8\u3057\u305f\u6642\u306b\u5b9f\u884c\u3059\u308b\u30a4\u30d9\u30f3\u30c8\u3067\u3059\u3002<br \/>\n<code>auto_login_token<\/code>\u3092\u521d\u671f\u5316\u3057\u307e\u3059\u3002<\/p>\n<pre>public function handle(<strong>Logout $event<\/strong>)\r\n{\r\n<strong>    $user = $event-&gt;user;<\/strong>\r\n<strong>    $user-&gt;auto_login_token = null;<\/strong>\r\n<strong>    $user-&gt;save();<\/strong>\r\n}<\/pre>\n<p>\u30ed\u30b0\u30a2\u30a6\u30c8\u3059\u308b\u3068\u3001\u6b21\u306e\u3088\u3046\u306b\u521d\u671f\u5316\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2892\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_3.png\" alt=\"\" width=\"123\" height=\"97\" \/><\/p>\n<h2>\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3URL\u3092\u4f5c\u6210\u3059\u308b<\/h2>\n<p>\u3067\u306f\u3001<code>Laravel<\/code>\u5074\u6700\u5f8c\u306e\u4f5c\u696d\u3068\u3057\u3066\u3001\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3URL\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u7c21\u5358\u306b\u3069\u3053\u304b\u3089\u3067\u3082\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3URL\u3092\u53d6\u5f97\u3067\u304d\u308b\u3088\u3046\u306bUser\u30e2\u30c7\u30eb\u306b<code>accessor<\/code>\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>\/\/ app\/User.php<\/strong>\r\n\r\nclass User extends Authenticatable\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>\/\/ Accessor<\/strong>\r\n<strong>    public function getAutoLoginUrlAttribute() {<\/strong>\r\n\r\n<strong>        return 'http:\/\/wordpress.example.com\/laravel-auto-login?token='. $this-&gt;auto_login_token;<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n}<\/pre>\n<p>\u3053\u308c\u3067\u3001<code>$user-&gt;auto_login_url<\/code>\u3068\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306a\u300c\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3URL\u300d\u304c\u53d6\u5f97\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>http:\/\/wordpress.example.com\/laravel-auto-login?token=1-rDvmDmQTrlFDx1NqHgOZkK4fGYRW0vGn<\/strong><\/pre>\n<p>\u306a\u304a\u3001<code>laravel-auto-login<\/code>\u3068\u3044\u3046\u30da\u30fc\u30b8\u306f\u3001\u3053\u308c\u304b\u3089\u30d7\u30e9\u30b0\u30a4\u30f3\u3067\u4f5c\u6210\u3059\u308b\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u5c02\u7528\u306e\u30da\u30fc\u30b8\u3067\u3059\u3002<\/p>\n<h1>wordpress\u5074\u306e\u4f5c\u696d<\/h1>\n<p>\u7d9a\u3044\u3066<code>wordpress<\/code>\u5074\u306e\u4f5c\u696d\u3067\u3059\u3002<\/p>\n<h2>\u6ce8\u610f\u70b9<\/h2>\n<p>\u4eca\u56de\u3082Laravel\u5074\u306eDB\u306b\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u304c\u3001\u3082\u3057<a href=\"https:\/\/blog.capilano-fw.com\/?p=2867\">\u524d\u56de\u8a18\u4e8b<\/a>\u3067\u4f5c\u3063\u305f\u72ec\u81ea\u30d7\u30e9\u30b0\u30a4\u30f3<code>laravel-authentication<\/code>\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u60c5\u5831\u306e\u90e8\u5206\u306f<code>wp-config.php<\/code>\u3078\u79fb\u52d5\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u3053\u3046\u3057\u306a\u3044\u3068\u5b9a\u7fa9\u304c\u91cd\u8907\u3057\u3066\u3044\u308b\u3068\u3057\u3066\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\uff09<\/p>\n<pre><strong>\/\/ wp-config.php<\/strong>\r\n\r\n\/\/ Laravel\u306eDB\u60c5\u5831\r\ndefine('LARAVEL_DB_TYPE', 'mysql');\r\ndefine('LARAVEL_DB_HOST', 'localhost');\r\ndefine('LARAVEL_DB_PORT', '3306');\r\ndefine('LARAVEL_DB_DATABASE', 'YOUR-LARAVEL-DB-NAME');\r\ndefine('LARAVEL_DB_USERNAME', 'YOUR-USER-NAME');\r\ndefine('LARAVEL_DB_PASSWORD', 'YOUR-PASSWORD');\r\ndefine('LARAVEL_DB_USER_TABLE', 'users'); \/\/ \u540d\u524d\u304c\u9055\u3046\u5834\u5408\u306f\u5909\u3048\u3066\u304f\u3060\u3055\u3044<\/pre>\n<h2>\u72ec\u81ea\u30d7\u30e9\u30b0\u30a4\u30f3\u958b\u767a\u306e\u6e96\u5099<\/h2>\n<p><code>wp-content\/plugins<\/code>\u30d5\u30a9\u30eb\u30c0\u306e\u4e2d\u306b<code>laravel-auto-login<\/code>\u30d5\u30a9\u30eb\u30c0\u3092\u4f5c\u6210\u3057\u3001\u305d\u306e\u4e2d\u306b<code>laravel-auto-login.php<\/code>\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2894\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_4.png\" alt=\"\" width=\"316\" height=\"188\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_4.png 316w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_4-300x178.png 300w\" sizes=\"auto, (max-width: 316px) 100vw, 316px\" \/><\/p>\n<h2>\u72ec\u81ea\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u3064\u304f\u308b<\/h2>\n<p>\u3067\u306f\u3001\u4eca\u56de\u306e\u8a18\u4e8b\u3067\u30e1\u30a4\u30f3\u306b\u306a\u308b\u72ec\u81ea\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\/*\r\nPlugin Name: Laravel Auto Login\r\nDescription: A plugin that allows to auto-login by Laravel users.\r\nVersion: 1.0.0\r\nAuthor: Sukohi Kuhoh\r\nAuthor URI: https:\/\/blog.capilano-fw.com\r\n*\/\r\n\r\n<strong>add_filter('wp', 'laravel_auto_login');<\/strong>\r\n\r\nfunction laravel_auto_login()\r\n{\r\n    global $wp;\r\n\r\n    \/\/ \u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u5c02\u7528\u30da\u30fc\u30b8\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\r\n    <strong>if($wp-&gt;request == 'laravel-auto-login') {<\/strong>\r\n\r\n        \/\/ DB\u63a5\u7d9a\r\n        <strong>try {<\/strong>\r\n\r\n<strong>            $pdo = new PDO(<\/strong>\r\n<strong>                LARAVEL_DB_TYPE . ':' .<\/strong>\r\n<strong>                'host=' . LARAVEL_DB_HOST . ';' .<\/strong>\r\n<strong>                'port=' . LARAVEL_DB_PORT . ';' .<\/strong>\r\n<strong>                'dbname=' . LARAVEL_DB_DATABASE . ';' .<\/strong>\r\n<strong>                'charset=utf8mb4', \/\/ DSN<\/strong>\r\n<strong>                LARAVEL_DB_USERNAME,<\/strong>\r\n<strong>                LARAVEL_DB_PASSWORD<\/strong>\r\n<strong>            );<\/strong>\r\n\r\n<strong>        } catch (Exception $e) {<\/strong>\r\n\r\n<strong>            throw new Exception('Failed to connect to database.');<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n        $token = trim($_GET['token']);\r\n\r\n        \/\/ \u30c8\u30fc\u30af\u30f3\u3092\u4f7f\u3063\u3066Laravel\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97\r\n        <strong>$sql = $pdo-&gt;prepare('SELECT id,name,email FROM ' . LARAVEL_DB_USER_TABLE . ' WHERE auto_login_token=:token');<\/strong>\r\n<strong>        $sql-&gt;bindParam(':token', $token);<\/strong>\r\n<strong>        $sql-&gt;execute();<\/strong>\r\n<strong>        $laravel_user = $sql-&gt;fetch();<\/strong>\r\n\r\n        if ($laravel_user) {\r\n\r\n            $laravel_name = $laravel_user['name'];\r\n            $laravel_email = $laravel_user['email'];\r\n            $password = md5(uniqid(rand(), 1));\r\n\r\n            $user_id = null;\r\n            $wp_user = get_user_by('email', $laravel_email);\r\n\r\n            <strong>if (!$wp_user) { \/\/ \u30e6\u30fc\u30b6\u30fc\u767b\u9332<\/strong>\r\n\r\n<strong>                $user_id = wp_insert_user([<\/strong>\r\n<strong>                    'user_login' =&gt; md5(uniqid(rand(), 1)),<\/strong>\r\n<strong>                    'user_pass' =&gt; $password,<\/strong>\r\n<strong>                    'user_email' =&gt; $laravel_email,<\/strong>\r\n<strong>                    'display_name' =&gt; $laravel_name,<\/strong>\r\n<strong>                    'role' =&gt; 'author'<\/strong>\r\n<strong>                ]);<\/strong>\r\n\r\n<strong>            } else { \/\/ \u30e6\u30fc\u30b6\u30fc\u66f4\u65b0<\/strong>\r\n\r\n<strong>                $user_id = $wp_user-&gt;ID;<\/strong>\r\n<strong>                wp_update_user([<\/strong>\r\n<strong>                    'ID' =&gt; $user_id,<\/strong>\r\n<strong>                    'user_pass' =&gt; $password,<\/strong>\r\n<strong>                    'user_email' =&gt; $laravel_email,<\/strong>\r\n<strong>                    'display_name' =&gt; $laravel_name<\/strong>\r\n<strong>                ]);<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n\r\n            \/\/ \u30e6\u30fc\u30b6\u30fcID\u3092\u4f7f\u3063\u3066\u30ed\u30b0\u30a4\u30f3\r\n            <strong>wp_set_current_user($user_id);<\/strong>\r\n<strong>            wp_set_auth_cookie($user_id);<\/strong>\r\n\r\n            \/\/ \u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u3078\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\r\n            <strong>wp_redirect('wp-admin\/');<\/strong>\r\n<strong>            exit();<\/strong>\r\n\r\n        }\r\n\r\n        \/\/ \u3053\u3053\u307e\u3067\u3067\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u306a\u304b\u3063\u305f\u3089\u5931\u6557\u3002Laravel\u3078\u30ea\u30c0\u30a4\u30ec\u30af\u30c8 \r\n<strong>        wp_redirect('http:\/\/laravel.example.com\/login'); \/\/ \u3054\u81ea\u8eab\u306eURL\u3078\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044<\/strong> <strong> \r\n        exit();<\/strong>\r\n\r\n    }\r\n\r\n}<\/pre>\n<p>\u3010\u8ffd\u8a18\uff1a2019.01.26\u3011\u30b3\u30fc\u30c9\u306b\u9593\u9055\u3044\u304c\u3042\u308a\u307e\u3057\u305f\u306e\u3067\u5909\u66f4\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f\u5185\u5bb9\u3092\u3072\u3068\u3064\u305a\u3064\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h3>\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u5c02\u7528\u30da\u30fc\u30b8\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af<\/h3>\n<p>\u307e\u305a\u3001\u3053\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u306f\u5168\u30da\u30fc\u30b8\u3067\u547c\u3073\u51fa\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u305d\u3057\u3066\u3001\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u5c02\u7528\u30da\u30fc\u30b8\u306eURL\uff08\u3064\u307e\u308a\u3001<code>http:\/\/******\/laravel-auto-login<\/code>\uff09\u306b\u30a2\u30af\u30bb\u30b9\u304c\u3042\u3063\u305f\u5834\u5408\u3060\u3051\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>DB\u63a5\u7d9a<\/h3>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u63a5\u7d9a\u306f\u524d\u56de\u306e<code>laravel-authentication<\/code>\u3068\u540c\u3058\u304f<code>PDO<\/code>\u3067\u3059\u3002<br \/>\n\u305f\u3060\u3057\u3001\u9055\u3063\u3066\u3044\u308b\u306e\u306fDB\u63a5\u7d9a\u306b\u5931\u6557\u3057\u305f\u5834\u5408\u306f\u4f8b\u5916\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u30c8\u30fc\u30af\u30f3\u3092\u4f7f\u3063\u3066Laravel\u30e6\u30fc\u30b6\u30fc\u3092\u53d6\u5f97<\/h3>\n<p>\u7d9a\u3044\u3066\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u30c8\u30fc\u30af\u30f3\u304b\u3089<code>Laravel<\/code>\u5074\u306e\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<h3>\u30e6\u30fc\u30b6\u30fc\u767b\u9332\uff06\u30e6\u30fc\u30b6\u30fc\u66f4\u65b0<\/h3>\n<p>\u3082\u3057<code>Laravel<\/code>\u306e\u30e6\u30fc\u30b6\u30fc\u304c\u898b\u3064\u304b\u3063\u305f\u5834\u5408\u3001<code>wordpress<\/code>\u306b\u540c\u3058\u30e6\u30fc\u30b6\u30fc\u304c\u5b58\u5728\u3057\u3066\u3044\u308b\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3001\u306a\u3051\u308c\u3070\u65b0\u898f\u767b\u9332\u3002\u3042\u308c\u3070\u305d\u306e\u30e6\u30fc\u30b6\u30fc\u30c7\u30fc\u30bf\u3092\u66f4\u65b0\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u3053\u3053\u306e\u51e6\u7406\u306f\u307b\u3068\u3093\u3069\u524d\u56de\u8a18\u4e8b\u3068\u540c\u3058\u3067\u3059\u304c\u3001\u305d\u308c\u305e\u308c\u30e6\u30fc\u30b6\u30fcID\u3092\u53d6\u5f97\u3057\u3066\u3044\u308b\u90e8\u5206\u304c\u9055\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u5f8c\u3067\u30e6\u30fc\u30b6\u30fc\u3092\u30ed\u30b0\u30a4\u30f3\u3055\u305b\u308b\u305f\u3081\u306b\u5fc5\u8981\u306b\u306a\u308b\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u60c5\u5831\u306f\u53d6\u5f97\u3067\u304d\u306a\u3044\u306e\u3067\u30e9\u30f3\u30c0\u30e0\u306a\u6587\u5b57\u5217\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u30e6\u30fc\u30b6\u30fcID\u3092\u4f7f\u3063\u3066\u30ed\u30b0\u30a4\u30f3<\/h3>\n<p><code>wordpress<\/code>\u5074\u306b\u30e6\u30fc\u30b6\u30fc\u304c\u6e96\u5099\u3067\u304d\u305f\u3089\u3001\u305d\u306e\u30e6\u30fc\u30b6\u30fcID\u3092\u4f7f\u3063\u3066\u30ed\u30b0\u30a4\u30f3\u3055\u305b\u307e\u3059\u3002<\/p>\n<h3>\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u3078\u30ea\u30c0\u30a4\u30ec\u30af\u30c8<\/h3>\n<p><code>wordpress<\/code>\u306b\u30ed\u30b0\u30a4\u30f3\u3055\u305b\u305f\u3089\u3001\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u3078\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u203b \u306a\u304a\u3001\u3082\u3057\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u306b\u5931\u6557\u3057\u305f\u3089<code>Laravel<\/code>\u306e\u30ed\u30b0\u30a4\u30f3\u30da\u30fc\u30b8\u3078\u79fb\u52d5\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h1>\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u6709\u52b9\u5316\u3059\u308b<\/h1>\n<p>\u3067\u306f\u3001\u6e96\u5099\u306f\u6574\u3044\u307e\u3057\u305f\u306e\u3067\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u6709\u52b9\u5316\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n\u30d7\u30e9\u30b0\u30a4\u30f3\u30da\u30fc\u30b8\u3067\u6b21\u306e\u30ea\u30f3\u30af\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2895\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_5.png\" alt=\"\" width=\"652\" height=\"133\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_5.png 652w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_5-300x61.png 300w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/p>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u6e96\u5099\u306f\u3059\u3079\u3066\u6574\u3063\u305f\u306e\u3067\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u307e\u305a\u3001<code>Laravel<\/code>\u306e<code>resources\/views\/home.blade.php<\/code>\u5185\u306b\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u306e\u30ea\u30f3\u30af\u3092\u4f5c\u6210\u3057\u3066\u30ed\u30b0\u30a4\u30f3\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>&lt;a href=\"{{ auth()-&gt;user()-&gt;auto_login_url }}\"&gt;\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3&lt;\/a&gt;<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3053\u306e\u3088\u3046\u306b\u30ea\u30f3\u30af\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2896\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_6.png\" alt=\"\" width=\"755\" height=\"162\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_6.png 755w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_6-300x64.png 300w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/p>\n<p>\u30af\u30ea\u30c3\u30af\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2897\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_7.png\" alt=\"\" width=\"1280\" height=\"721\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_7.png 1280w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_7-300x169.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_7-768x433.png 768w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/12\/laravel_wordpress_auto_login_7-1024x577.png 1024w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>\u3046\u307e\u304f\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u307e\u3057\u305f\uff01<\/p>\n<p>\u4eca\u56de\u306f\u4ee5\u4e0a\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\u3002<\/p>\n<h1>\u304a\u307e\u3051 &#8211; 1\uff08\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u3092\u5411\u4e0a\u3055\u305b\u308b\uff09<\/h1>\n<p>\u3061\u306a\u307f\u306b\u8ffd\u52a0\u3059\u308b\u304b\u3069\u3046\u304b\u8ff7\u3063\u305f\u7d50\u679c\u3001\u3067\u304d\u308b\u3060\u3051\u6839\u672c\u7684\u306a\u90e8\u5206\u3092\u7d39\u4ecb\u3059\u308b\u305f\u3081\u306b\u7701\u3044\u305f\u6a5f\u80fd\u3092\u304a\u307e\u3051\u3068\u3057\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><s>\u4eca\u56de\u7d39\u4ecb\u3057\u305f\u5185\u5bb9\u3060\u3068\u3001\u30a2\u30af\u30bb\u30b9\u30c8\u30fc\u30af\u30f3\u306f\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u3068\u304d\u306b\u3060\u3051\u66f4\u65b0\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u53ef\u80fd\u6027\u3068\u3057\u3066\u306f\u305d\u306e\u5f8c\u9577\u3044\u9593\u30c8\u30fc\u30af\u30f3\u304c\u540c\u3058\u307e\u307e\u306b\u306a\u308b\u5834\u5408\u3082\u3042\u308b\u308f\u3051\u3067\u3059\u3002\u3053\u308c\u306f\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u4e0a\u3042\u307e\u308a\u3044\u3044\u3068\u306f\u8a00\u3048\u307e\u305b\u3093\u3002<\/s><\/p>\n<p><strong>\u3010\u8ffd\u8a18\uff1a 2019.01.26\u3011<\/strong> <code>LogAuthenticated<\/code>\u3092\u4f7f\u3063\u3066\u5b9f\u88c5\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u30ed\u30b0\u30a4\u30f3\u4e2d\u306b\u30da\u30fc\u30b8\u79fb\u52d5\u304c\u3042\u308c\u3070\u6bce\u56de\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u306e\u30c8\u30fc\u30af\u30f3\u306f\u66f4\u65b0\u3055\u308c\u307e\u3059\u3002\u5185\u5bb9\u304c\u6b63\u78ba\u3067\u306f\u306a\u304f\u7533\u3057\u8a33\u3054\u3056\u3044\u307e\u305b\u3093\u3002\u305d\u306e\u305f\u3081\u3001\u4ee5\u4e0b\u306e\u5185\u5bb9\u306f\u3082\u3057<code>LoginController.php<\/code>\u3067\u5b9f\u88c5\u3057\u3066\u3044\u305f\u5834\u5408\u306b\u8ffd\u52a0\u3059\u308b\u5185\u5bb9\u3068\u3057\u3066\u304a\u8aad\u307f\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u30fb\u30c8\u30fc\u30af\u30f3\u304c\u4f7f\u3048\u308b\u306e\u306f\u4e00\u56de\u3060\u3051\u306b\u3057\u3001\u3055\u3089\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u308c\u3070\u30da\u30fc\u30b8\u79fb\u52d5\u3059\u308b\u5ea6\u306b\u30c8\u30fc\u30af\u30f3\u3092\u66f4\u65b0\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<h2>\u30da\u30fc\u30b8\u3092\u79fb\u52d5\u3059\u308b\u5ea6\u306b\u30c8\u30fc\u30af\u30f3\u3092\u66f4\u65b0\u3059\u308b<\/h2>\n<p>\u307e\u305a\u3001<code>Laravel<\/code>\u5074\u3067\u3059\u3002<\/p>\n<p>\u30da\u30fc\u30b8\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u5ea6\u306b\u30ed\u30b0\u30a4\u30f3\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u305f\u3081\u306b<code>UpdateAutoLoginToken<\/code>\u3068\u3044\u3046\u540d\u524d\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u4f5c\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan make:middleware UpdateAutoLoginToken<\/strong><\/pre>\n<p>\u4e2d\u8eab\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002\uff08\u592a\u5b57\u304c\u8ffd\u52a0\u3057\u305f\u90e8\u5206\u3067\u3059\uff09<\/p>\n<pre>public function handle($request, Closure $next)\r\n{\r\n<strong>    if(auth()-&gt;check()) {<\/strong>\r\n\r\n<strong>        $user = $request-&gt;user();<\/strong>\r\n<strong>        $user-&gt;auto_login_token = $user-&gt;id .'-'. str_random(32);<\/strong>\r\n<strong>        $user-&gt;save();<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n    return $next($request);\r\n}<\/pre>\n<p>\u305d\u3057\u3066\u3001\u3053\u306e\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092<code>app\/Http\/Kernel.php<\/code>\u306b\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<pre>protected $middlewareGroups = [\r\n    'web' =&gt; [\r\n\r\n        \/\/ \u7701\u7565\r\n\r\n        <strong>\\App\\Http\\Middleware\\UpdateAutoLoginToken::class<\/strong>\r\n    ],\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n];<\/pre>\n<p>\u3053\u308c\u3067\u3001\u30ed\u30b0\u30a4\u30f3\u72b6\u614b\u3067\u3042\u308c\u3070\u30da\u30fc\u30b8\u79fb\u52d5\u3057\u305f\u3068\u304d\u306b\u5fc5\u305a\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u30fb\u30c8\u30fc\u30af\u30f3\u3092\u66f4\u65b0\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u3089\u30c8\u30fc\u30af\u30f3\u3092\u524a\u9664\u3059\u308b<\/h2>\n<p>\u6b21\u306b<code>wordpress<\/code>\u5074\u3067\u3059\u3002<br \/>\n\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u304c\u6210\u529f\u3057\u305f\u6642\u70b9\u3067\u30c8\u30fc\u30af\u30f3\u3092\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n<pre>\/\/ \u30e6\u30fc\u30b6\u30fcID\u3092\u4f7f\u3063\u3066\u30ed\u30b0\u30a4\u30f3\r\n\r\n\/\/ \u7701\u7565\r\n\r\n<strong>\/\/ Laravel\u5074\u306e\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u30c8\u30fc\u30af\u30f3\u3092\u521d\u671f\u5316<\/strong>\r\n<strong>$sql = $pdo-&gt;prepare('UPDATE '. LARAVEL_DB_USER_TABLE .' SET auto_login_token = :token');<\/strong>\r\n<strong>$sql-&gt;bindValue(':token', null, PDO::PARAM_NULL);<\/strong>\r\n<strong>$sql-&gt;execute();<\/strong>\r\n\r\n\/\/ \u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u3078\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\r\n\r\n\/\/ \u7701\u7565<\/pre>\n<p>\u3053\u308c\u3067\u3088\u308a\u30bb\u30ad\u30e5\u30a2\u306a\u30b5\u30a4\u30c8\u69cb\u6210\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<h1>\u304a\u307e\u3051 &#8211; 2\uff08\u30c8\u30fc\u30af\u30f3\u66f4\u65b0\u3092\u4e00\u5143\u7ba1\u7406\u3059\u308b\uff09<\/h1>\n<p>\u4eca\u56de\u306f\u8aac\u660e\u306e\u305f\u3081\u306b\u5404\u5834\u6240\u3067\u30c8\u30fc\u30af\u30f3\u3092\u66f4\u65b0\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u8907\u6570\u56de\u547c\u3070\u308c\u308b\u30b3\u30fc\u30c9\u306f\u4e00\u5143\u7ba1\u7406\u3059\u3079\u304d\u3067\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u6b21\u306e\u3088\u3046\u306a\u6b21\u306e\u3088\u3046\u306a\u30e1\u30bd\u30c3\u30c9\u3092\u7528\u610f\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>\/\/ User.php<\/strong>\r\n\r\npublic function updateAutoLoginToken() {\r\n\r\n    $this-&gt;auto_login_token = $this-&gt;id .'-'. str_random(32);\r\n    $this-&gt;save();\r\n\r\n}<\/pre>\n<p>\u4f7f\u3044\u65b9\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>$user-&gt;updateAutoLoginToken();<\/strong><\/pre>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u524d\u56de\u306b\u5f15\u304d\u7d9a\u304d<code>Laravel<\/code>\u3068<code>wordpress<\/code>\u3092\u7d71\u5408\u3059\u308b\u8a71\u984c\u3092\u304a\u5c4a\u3051\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u4eca\u56de\u306e\u72ec\u81ea\u30d7\u30e9\u30b0\u30a4\u30f3\u306f\u524d\u56de\u306e<code>laravel-authentication<\/code>\u3068\u4f75\u7528\u3067\u304d\u308b\u306e\u3067\u3001<code>wordpress<\/code>\u306e\u30ed\u30b0\u30a4\u30f3\u30da\u30fc\u30b8\u304b\u3089<code>Laravel<\/code>\u306e\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3067\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u8a18\u4e8b\u4e2d\u3067\u3082\u8a00\u3044\u307e\u3057\u305f\u304c\u3001<code>define()<\/code>\u90e8\u5206\u304c\u91cd\u8907\u3057\u3066\u3057\u307e\u3046\u3068PHP\u30a8\u30e9\u30fc\uff08\u5b9f\u969b\u306b\u306fNotice\uff09\u304c\u767a\u751f\u3057\u3066\u3057\u307e\u3046\u306e\u3067\u3001<code>wp-config.php<\/code>\u3078\u79fb\u52d5\u3055\u305b\u307e\u3057\u305f\u3002<\/p>\n<p>\u3082\u3061\u308d\u3093\u6211\u3005\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u3060\u3051\u304c\u4f7f\u3046\u5206\u306b\u306f\u3053\u306e\u5f62\u3067\u3082\u3044\u3044\u306e\u3067\u3057\u3087\u3046\u304c\u3001\u901a\u5e38\u306e\u30e6\u30fc\u30b6\u30fc\u304c\u4f7f\u3046\u5834\u5408\u306b\u306f\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u7de8\u96c6\u3068\u3044\u3046\u306e\u306f\u5c11\u3057\u6016\u304b\u3063\u305f\u308a\u3082\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u3082\u3057\u6c17\u306b\u306a\u308b\u3088\u3046\u3067\u3057\u305f\u3089<code>wordpress<\/code>\u306e\u8a2d\u5b9a\u30da\u30fc\u30b8\u3067DB\u3078\u306e\u63a5\u7d9a\u60c5\u5831\u3092\u7de8\u96c6\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002\uff08\u6c17\u304c\u5411\u3044\u305f\u3089\u3053\u306e\u90e8\u5206\u3082\u8a18\u4e8b\u306b\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u306d\uff09<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2597 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2.png\" alt=\"\" width=\"275\" height=\"350\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2.png 275w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/15-2-236x300.png 236w\" sizes=\"auto, (max-width: 275px) 100vw, 275px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u524d\u56de\u00a0Laravel\u306e\u30e6\u30fc\u30b6\u30fc\u3067wordpress\u3078\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b \u3067\u306f\u3001Laravel\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u4f7f\u3063\u3066wordpres &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=2889\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u30ed\u30b0\u30a4\u30f3\u4e2d\u306eLaravel\u30e6\u30fc\u30b6\u30fc\u3067wordpress\u3078\u81ea\u52d5\u30ed\u30b0\u30a4\u30f3\u3059\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":2900,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,59],"tags":[58],"class_list":["post-2889","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","category-wordpress","tag-58"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2889","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=2889"}],"version-history":[{"count":8,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2889\/revisions"}],"predecessor-version":[{"id":3296,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2889\/revisions\/3296"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/2900"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}