{"id":420,"date":"2018-04-04T19:05:18","date_gmt":"2018-04-04T10:05:18","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=420"},"modified":"2019-12-24T16:59:35","modified_gmt":"2019-12-24T07:59:35","slug":"%e3%82%b7%e3%83%b3%e3%83%97%e3%83%ab%ef%bc%81laravel5-6%e3%81%a7%e3%80%8c%e6%a8%a9%e9%99%90%e3%81%a4%e3%81%8d%e3%80%8d%e3%83%ad%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%95%e3%81%9b%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=420","title":{"rendered":"\u30b7\u30f3\u30d7\u30eb\uff01Laravel5.6\u3067\u300c\u6a29\u9650\u3064\u304d\u300d\u30ed\u30b0\u30a4\u30f3\u3055\u305b\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u6bce\u56de\u8a00\u3063\u3066\u307e\u3059\u3051\u3069Laravel\u306b\u306f\u6700\u521d\u304b\u3089\u5f37\u529b\u306a\u6a5f\u80fd\u304c\u305f\u304f\u3055\u3093\u5099\u308f\u3063\u3066\u3044\u3066\u3001\u958b\u767a\u52b9\u7387\u304c\u98db\u8e8d\u7684\u306b\u5411\u4e0a\u3059\u308b\u3053\u3068\u9593\u9055\u3044\u306a\u3057\u3060\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3001\u305d\u3093\u306a\u4e2d\u306b\u3042\u3063\u3066\u3082\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u3064\u3044\u3066\u3044\u306a\u3044\u6a5f\u80fd\u3082\u3042\u3063\u3066\u3001\u300c<strong>\u6a29\u9650\u3064\u304d\u306e\u30ed\u30b0\u30a4\u30f3<\/strong>\u300d\u3082\u305d\u306e\u3072\u3068\u3064\u3067\u3059\u3002<\/p>\n<h1>\u6a29\u9650\u3064\u304d\u30ed\u30b0\u30a4\u30f3\u3068\u306f\uff1f<\/h1>\n<p>\u300c\u6a29\u9650\u3064\u304d\u30ed\u30b0\u30a4\u30f3\u300d\u3068\u3044\u3046\u306e\u306f\u3001\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u306b<strong>\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\u304c\u5206\u304b\u308b\u60c5\u5831\u3092\u8ffd\u52a0\u3057\u305f\u3082\u306e<\/strong>\u3067\u3001<\/p>\n<ul>\n<li><strong>\u7ba1\u7406\u8005\u3060\u3051\u304c\u95b2\u89a7\u3067\u304d\u308b\u30da\u30fc\u30b8<\/strong><\/li>\n<li><strong>\u304a\u5ba2\u3055\u3093\u306b\u306f\u898b\u305b\u305f\u304f\u306a\u3044\u30da\u30fc\u30b8<\/strong><\/li>\n<li><strong>\u901a\u5e38\u30e6\u30fc\u30b6\u30fc\u3060\u3051\u306b\u8868\u793a\u3059\u308b\u30a4\u30d9\u30f3\u30c8\u60c5\u5831<\/strong><\/li>\n<\/ul>\n<p>\u3068\u3044\u3063\u305f\u3001\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\u3067\u3044\u308d\u3044\u308d\u306a\u5207\u308a\u66ff\u3048\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u7df4\u7fd2\u3068\u3057\u3066\u4ee5\u4e0b\uff12\u3064\u3067\u30ed\u30b0\u30a4\u30f3\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<ul>\n<li><strong>owner\u3000\u30fb\u30fb\u30fb\u3000\u304a\u5e97\u306e\u30aa\u30fc\u30ca\u30fc<\/strong><\/li>\n<li><strong>customer\u3000\u30fb\u30fb\u30fb\u3000\u304a\u5ba2\u3055\u3093<\/strong><\/li>\n<\/ul>\n<h1>\u76ee\u6307\u3059\u6a5f\u80fd<\/h1>\n<p>\u30b4\u30fc\u30eb\u306f\u3001<\/p>\n<ul>\n<li><strong>\u304a\u5e97\u306e\u30aa\u30fc\u30ca\u30fc\u3060\u3051\u8868\u793a\u3067\u304d\u308b\u30da\u30fc\u30b8<\/strong><\/li>\n<li><strong>\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u308c\u3070\u8ab0\u3067\u3082\u8868\u793a\u3067\u304d\u308b\u30da\u30fc\u30b8<\/strong><\/li>\n<\/ul>\n<p>\u3092\u3064\u304f\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u3084\u3063\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/p>\n<p>\u203b\u524d\u63d0\u3068\u3057\u3066\u3001\u300cphp artisan make:auth\u300d\u3067\u901a\u5e38\u30ed\u30b0\u30a4\u30f3\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u3082\u306e\u3068\u3057\u307e\u3059\u3002\u307e\u3060\u3084\u3063\u3066\u306a\u3044\u4eba\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>\u3092\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u300c\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\u300d\u9805\u76ee\u3092\u8ffd\u52a0<\/h1>\n<p>Laravel\u306e\u30e6\u30fc\u30b6\u30fc\u306f\u300cusers\u300d\u30c6\u30fc\u30d6\u30eb\u3067\u7ba1\u7406\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u3053\u306b\u300c<strong>role<\/strong>\uff08\u5f79\u5272\uff09\u300d\u3068\u3044\u3046\u9805\u76ee\u3092\u8ffd\u52a0\u3057\u3066\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\u3092\u7ba1\u7406\u3057\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u69cb\u9020\u3092\u5909\u66f4\u3059\u308b\u306e\u3067\u3001\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan make:migration add_role_to_users<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001<strong>\/database\/migrations<\/strong>\u306e\u4e2d\u306b\u65b0\u3057\u3044\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u3066\u308b\u306e\u3067\u3001\u6b21\u306e\u3088\u3046\u306brole\u3092\u8ffd\u52a0\u3059\u308b\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre>public function up()\r\n{\r\n<strong>    Schema::table('users', function (Blueprint $table) {<\/strong>\r\n<strong>        $table-&gt;string('role')-&gt;after('password');<\/strong>\r\n<strong>    });<\/strong>\r\n}\r\n\r\npublic function down()\r\n{\r\n<strong>    Schema::table('users', function (Blueprint $table) {<\/strong>\r\n<strong>        $table-&gt;dropColumn('role');<\/strong>\r\n<strong>    });<\/strong>\r\n}<\/pre>\n<p>\u4e2d\u8eab\u3068\u3057\u3066\u306f\u3001<\/p>\n<ul>\n<li><strong>up()\u3067\u300crole<\/strong><strong>\u300d\u3092\u8ffd\u52a0\u3059\u308b<\/strong><\/li>\n<li><strong>down()\u3067\u300crole\u300d\u3092\u524a\u9664\u3059\u308b<\/strong><\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u30b3\u30fc\u30c9\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u203b\u3061\u306a\u307f\u306b\u3001after()\u306e\u90e8\u5206\u306f\u300crole\u300d\u306e\u4f4d\u7f6e\u3092\u5909\u66f4\u3059\u308b\u8a18\u8ff0\u3067\u3001password\u306e\u5f8c\u306b\u304f\u308b\u3088\u3046\u79fb\u52d5\u3055\u305b\u3066\u3044\u307e\u3059\u3002\u3082\u3061\u308d\u3093\u4e00\u756a\u6700\u5f8c\u3067\u3082\u554f\u984c\u306a\u3044\u3067\u3059\u3051\u3069\u3001\u306a\u3093\u3060\u304b\u300c\u6574\u9813\u3055\u308c\u3066\u3044\u306a\u3044\u611f\u300d\u304c\u51fa\u3066\u3057\u307e\u3046\u306e\u3067\u3088\u304f\u5229\u7528\u3057\u3066\u3044\u307e\u3059\uff08\u7b11\uff09<\/p>\n<p>\u30b3\u30fc\u30c9\u304c\u5b8c\u6210\u3057\u305f\u3089\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\uff08\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u69cb\u9020\u306e\u5909\u66f4\uff09\u3092\u5b9f\u884c\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan migrate<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001role\u3092\u8ffd\u52a0\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-422\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/added_role_to_users.png\" alt=\"\" width=\"379\" height=\"254\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/added_role_to_users.png 379w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/added_role_to_users-300x201.png 300w\" sizes=\"auto, (max-width: 379px) 100vw, 379px\" \/><\/p>\n<p>\u3082\u3057\u3001\u3082\u3068\u306b\u623b\u3057\u305f\u3044\u5834\u5408\u306f\u3001<\/p>\n<pre><strong>php artisan migrate:rollback<\/strong><\/pre>\n<p>\u3067\u300crole\u300d\u3092\u524a\u9664\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u3053\u306e\u8fba\u3082Laravel\u306e\u4fbf\u5229\u306a\u6a5f\u80fd\u306e\u3072\u3068\u3064\u3067\u3059\u306d\uff01<\/p>\n<p>\u3067\u306f\u3001\u30c6\u30b9\u30c8\u30e6\u30fc\u30b6\u30fc\u3068\u3057\u3066\u300cowner\u300d\u3068\u300ccustomer\u300d\uff12\u4eba\u306e\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u30c7\u30fc\u30bf\u306e\u8ffd\u52a0\u306fSeeder\u6a5f\u80fd\u3092\u4f7f\u3046\u3068\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<p>\u30b3\u30de\u30f3\u30c9\u304b\u3089Seeder\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan make:seeder UsersTableSeeder<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001\u300c<strong>\/database\/seeds<\/strong>\u300d\u30d5\u30a9\u30eb\u30c0\u306e\u4e2d\u306b\u300c<strong>UsersTableSeeder.php<\/strong>\u300d\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30e6\u30fc\u30b6\u30fc\u8ffd\u52a0\u3059\u308b\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>public function run()\r\n{\r\n    \/\/ \u30aa\u30fc\u30ca\u30fc\r\n    \\App\\User::create([\r\n        'name' =&gt; '\u30aa\u30fc\u30ca\u30fc\u592a\u90ce',\r\n        'email' =&gt; 'owner@example.com',\r\n        'password' =&gt; bcrypt('xxxxxxxx'),\r\n        <strong>'role' =&gt; 'owner'<\/strong>\r\n    ]);\r\n\r\n    \/\/ \u304a\u5ba2\u3055\u3093\r\n    \\App\\User::create([\r\n        'name' =&gt; '\u304a\u5ba2\u82b1\u5b50',\r\n        'email' =&gt; 'customer@example.com',\r\n        'password' =&gt; bcrypt('xxxxxxxx'),\r\n        <strong>'role' =&gt; 'customer'<\/strong>\r\n    ]);\r\n}<\/pre>\n<p>\u203b\u3061\u306a\u307f\u306b\u3001role\u306f\u300croles\u300d\u30c6\u30fc\u30d6\u30eb\u306a\u3069\u3092\u4f5c\u3063\u3066\u304a\u3044\u305f\u65b9\u304c\u3088\u308a\u6574\u7406\u3057\u3084\u3059\u3044\u3093\u3067\u3057\u3087\u3046\u3051\u3069\u3001\u4eca\u56de\u306f\u308f\u304b\u308a\u3084\u3059\u3055\u91cd\u8996\u3067\u76f4\u63a5role\u306b\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002\u3082\u3057\u304f\u306f\u3001\u30d4\u30dc\u30c3\u30c8\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3063\u3066\u3082\u3044\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u30b3\u30fc\u30c9\u304c\u66f8\u304d\u7d42\u308f\u3063\u305f\u3089\u3001\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan migrate:fresh --seed<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001\u300cusers\u300d\u30c6\u30fc\u30d6\u30eb\u306b\u300c\u30aa\u30fc\u30ca\u30fc\u300d\u3068\u300c\u304a\u5ba2\u3055\u3093\u300d\u306e\uff12\u30e6\u30fc\u30b6\u30fc\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-421\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/users_2_roles.png\" alt=\"\" width=\"956\" height=\"102\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/users_2_roles.png 956w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/users_2_roles-300x32.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/users_2_roles-768x82.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<h1>\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\u3092\u5224\u5225\u3059\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u304f\uff08Middleware\uff09<\/h1>\n<p>\u3067\u306f\u3001\u6b21\u306b\u30ed\u30b0\u30a4\u30f3\u30e6\u30fc\u30b6\u30fc\u306e\u300c\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\u300d\u3092\u5224\u5225\u3059\u308b\u90e8\u5206\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u5f8c\u3067\u8aac\u660e\u3057\u307e\u3059\u304c\u3001<strong>\u3053\u3053\u3067\u4f5c\u308b\u30b3\u30fc\u30c9\u3092route\u304b\u3089\u547c\u3073\u51fa\u3059\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/strong><\/p>\n<p>\u5229\u7528\u3059\u308bLaravel\u306e\u6a5f\u80fd\u306f\u300c<strong>middleware<\/strong>\u300d\u3067\u3059\u3002<br \/>\n\u3053\u308c\u3067\u3001owner\u304b\u3069\u3046\u304b\u3092\u5224\u5225\u3059\u308b\u90e8\u5206\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3053\u308c\u3082\u5c02\u7528\u30b3\u30de\u30f3\u30c9\u304c\u3042\u308b\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9f\u884c\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:middleware OwnerAuth<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u300c<strong>\/app\/Http\/Middleware<\/strong>\u300d\u306b\u300c<strong>OwnerAuth.php<\/strong>\u300d\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u3053\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre>    public function handle($request, Closure $next)\r\n    {\r\n        <strong>if(auth()-&gt;check() &amp;&amp; auth()-&gt;user()-&gt;role == 'owner')<\/strong> {\r\n\r\n            return $next($request);\r\n\r\n        }\r\n\r\n        <strong>return redirect('\/');<\/strong>\r\n    }\r\n}<\/pre>\n<p>\u5185\u5bb9\u3068\u3057\u3066\u306f\u3001<\/p>\n<ul>\n<li><strong>\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u306e\u300c<\/strong><strong>role\u300d\u304c\u300cowner\u300d\u306a\u3089OK\u3002<\/strong><\/li>\n<li><strong>\u305d\u308c\u4ee5\u5916\u306a\u3089\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b<\/strong><\/li>\n<\/ul>\n<p>\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u3044\u3061\u3044\u3061role\u3092\u547c\u3073\u51fa\u3059\u306e\u306f\u3081\u3093\u3069\u304f\u3055\u3044\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u300cusers\u300d\u30c6\u30fc\u30d6\u30eb\u306baccessor\u3092\u4f5c\u3063\u3066\u304a\u304f\u3068\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<pre><strong>public function getIsOwnerAttribute() {\r\n\r\n    return (auth()-&gt;user()-&gt;role == 'owner');\r\n\r\n}<\/strong><\/pre>\n<p>\u4eca\u56de\u3067\u8a00\u3046\u3068\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<pre>if(auth()-&gt;check() &amp;&amp; <strong>auth()-&gt;user()-&gt;is_owner<\/strong>) {\r\n\r\n    return $next($request);\r\n\r\n}<\/pre>\n<p>\u3067\u306f\u3001\u3053\u306emiddleware\u3092Route\u304b\u3089\u547c\u3073\u51fa\u305b\u308b\u3088\u3046\u306b\u300c\/app\/Http\/Kernel.php\u300d\u306b\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>use App\\Http\\Middleware\\OwnerAuth;<\/strong><\/pre>\n<pre>protected $routeMiddleware = [\r\n    \/* \u7701\u7565 *\/\r\n    <strong>'owner_auth' =&gt; OwnerAuth::class,<\/strong>\r\n];<\/pre>\n<p>\u203b\u30cd\u30fc\u30e0\u30b9\u30da\u30fc\u30b9\uff08use ****\uff09\u3082\u5fd8\u308c\u305a\u306b\uff01<\/p>\n<p>\u3053\u308c\u3067\u547c\u3073\u51fa\u3057\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<h1>Route\u306b\u6a29\u9650\u3092\u30bb\u30c3\u30c8\u3059\u308b<\/h1>\n<p>\u3067\u306f\u3001\u6b21\u306bRoute\u306b\u6a29\u9650\u3092\u30bb\u30c3\u30c8\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u3001<\/p>\n<pre><strong>http:\/\/*****.test\/owner\/home<\/strong><\/pre>\n<p>\u304c\u7ba1\u7406\u8005\u5c02\u7528\u306e\u30da\u30fc\u30b8\u306b\u306a\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\uff08\u3064\u307e\u308a\u3001\u304a\u5ba2\u3055\u3093\u30e6\u30fc\u30b6\u30fc\u306a\u3089\u8868\u793a\u305b\u305a\u3001\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\uff09<\/p>\n<p>Laravel\u306eRoute\u30d5\u30a1\u30a4\u30eb\u306f\u3044\u304f\u3064\u304b\u308a\u307e\u3059\u304c\u3001\u57fa\u672c\u306f\u300c<strong>\/routes\/web.php<\/strong>\u300d\u3067\u3059\u3002<br \/>\n\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u3001\u3055\u3063\u304d\u4f5c\u3063\u305fMiddleware\u3092\u30bb\u30c3\u30c8\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>Route::group([<strong>'middleware' =&gt; 'owner_auth'<\/strong>], function () {\r\n\r\n    Route::get('\/owner\/home', 'Owner\\HomeController@index');\r\n\r\n});<\/pre>\n<p>\u91cd\u8981\u306a\u306e\u306f\u3001<\/p>\n<pre>Route::group([<strong>'middleware' =&gt; 'owner_auth'<\/strong>], function () { \/* \u7701\u7565 *\/ }<\/pre>\n<p>\u306e\u90e8\u5206\u3067\u3059\u3002\u3053\u308c\u306f\u3001<\/p>\n<ul>\n<li>\u30b0\u30eb\u30fc\u30d7\u3092\u4f5c\u308a\u307e\u3059\u3002<\/li>\n<li>\u305d\u3057\u3066\u3001\u305d\u306e\u30b0\u30eb\u30fc\u30d7\u306f\u300cowner_auth\u300d\u3068\u3044\u3046Middleware\u3092\u30bb\u30c3\u30c8\u3057\u307e\u3059<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u5b9f\u969b\u306e\u958b\u767a\u3067\u306fprefix\u3092\u4f7f\u3063\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30b3\u30fc\u30c9\u91cf\u3092\u6e1b\u3089\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<pre><strong>Route::group(['prefix' =&gt; 'owner', 'middleware' =&gt; 'owner_auth'], function () {<\/strong>\r\n\r\n<strong>    Route::get('\/home', 'Owner\\HomeController@index');<\/strong>\r\n<strong>    Route::get('\/home2', 'Owner\\HomeController@index2');<\/strong>\r\n<strong>    Route::get('\/home3', 'Owner\\HomeController@index3');<\/strong>\r\n\r\n<strong>});<\/strong><\/pre>\n<p>\u3067\u306f\u3001Owner\\HomeController\u3092\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u4f5c\u6210\u3057\u3066\u4e2d\u8eab\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan make:controller Owner\\\\HomeController<\/strong><\/pre>\n<p>\u30c6\u30b9\u30c8\u306a\u306e\u3067\u3001\u30b7\u30f3\u30d7\u30eb\u306bOK\u3060\u3051\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>public function index() {<\/strong>\r\n\r\n<strong>    return 'OK';<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<p>\u306f\u3044\u3002\u3053\u308c\u3067\u6e96\u5099\u306f\u5b8c\u4e86\u3067\u3059\u3002<br \/>\n\u5b9f\u969b\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u307f\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h1>\u30aa\u30fc\u30ca\u30fc\u3068\u304a\u5ba2\u3055\u3093\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u6319\u52d5\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b<\/h1>\n<p>\u3053\u306e\u72b6\u614b\u3067\u3001\u307e\u305a\u30aa\u30fc\u30ca\u30fc\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u300chttp:\/\/*****.test\/owner\/home\u300d\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-423\" style=\"border: 3px solid #555;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/owner_auth_ok.png\" alt=\"\" width=\"221\" height=\"97\" \/><\/p>\n<p>\u3046\u307e\u304f\u3044\u304d\u307e\u3057\u305f\u3002<br \/>\n\u3067\u306f\u3001\u4e00\u65e6\u30ed\u30b0\u30a2\u30a6\u30c8\u3057\u3066\u300c\u304a\u5ba2\u3055\u3093\u300d\u30e6\u30fc\u30b6\u30fc\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-424\" style=\"border: 3px solid #555;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/customer_user_login.png\" alt=\"\" width=\"502\" height=\"217\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/customer_user_login.png 502w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/customer_user_login-300x130.png 300w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><\/p>\n<p>\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u306b\u81ea\u52d5\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-426\" style=\"border: 3px solid #555;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/laravel_top.png\" alt=\"\" width=\"841\" height=\"339\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/laravel_top.png 841w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/laravel_top-300x121.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/laravel_top-768x310.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>\u3053\u308c\u3067\u300c\u30aa\u30fc\u30ca\u30fc\u300d\u5c02\u7528\u30da\u30fc\u30b8\u3092\u4ed6\u306e\u30ed\u30b0\u30a4\u30f3\u30e6\u30fc\u30b6\u30fc\u304b\u3089\u5b88\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<h1>\u3061\u306a\u307f\u306b<\/h1>\n<p><a href=\"https:\/\/blog.capilano-fw.com\/?p=405\">\u5fc5\u898b\uff01Laravel\uff085.6\uff09\u306eBlade\u3067\u3067\u304d\u308b\u3053\u3068\u300c\u307e\u3068\u3081\u300d<\/a>\u3067\u3082\u89e6\u308c\u307e\u3057\u305f\u3051\u3069\u3001\u540c\u3058\u3088\u3046\u306b\u3084\u308b\u3068Blade\u306e\u4e2d\u3067\u300cowner\u300d\u304b\u300ccustomer\u300d\u304b\u3092\u5224\u5225\u3059\u308b\u72ec\u81ea\u306eif\u6587\u3092\u3064\u304f\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001\u300c<strong>\/app\/Providers\/AppServiceProvider.php<\/strong>\u300d\u306eboot()\u5185\u306b\u3001\u6b21\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre>\\Blade::if('owner', function () {\r\n    return (auth()-&gt;check() &amp;&amp; auth()-&gt;user()-&gt;is_owner);\r\n});<\/pre>\n<p>\u305d\u3057\u3066\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u4e2d\u3067\u3001<\/p>\n<pre>@owner\r\n    \u30aa\u30fc\u30ca\u30fc\u3055\u3093\u3001\u3044\u3064\u3082\u304a\u3064\u304b\u308c\u69d8\u3067\u3059\uff01\r\n@endowner<\/pre>\n<p>\u3068\u3059\u308b\u3068\u3001\u300cowner\u300d\u30e6\u30fc\u30b6\u30fc\u3060\u3051\u306b\u300c\u30aa\u30fc\u30ca\u30fc\u3055\u3093\u3001\u3044\u3064\u3082\u304a\u3064\u304b\u308c\u69d8\u3067\u3059\uff01\u300d\u3068\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u3092\u4f7f\u3048\u3070\u3001\u300c\u304a\u5ba2\u3055\u3093\u3060\u3051\u306b\u7279\u58f2\u60c5\u5831\u3092\u8868\u793a\u3059\u308b\u300d\u306a\u3069\u3082\u3067\u304d\u307e\u3059\u306d\uff01<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u6a29\u9650\u3064\u304d\u30ed\u30b0\u30a4\u30f3\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u5b9f\u88c5\u306b\u306f\u3044\u308d\u3044\u308d\u65b9\u6cd5\u304c\u3042\u308b\u306e\u3067\u3053\u308c\u3082\u3072\u3068\u3064\u306e\u3084\u308a\u65b9\u3060\u3068\u601d\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-427 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24.png\" alt=\"\" width=\"182\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24.png 182w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/24-171x300.png 171w\" sizes=\"auto, (max-width: 182px) 100vw, 182px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u6bce\u56de\u8a00\u3063\u3066\u307e\u3059\u3051\u3069Laravel\u306b\u306f\u6700\u521d\u304b\u3089\u5f37\u529b\u306a\u6a5f\u80fd\u304c\u305f\u304f\u3055\u3093\u5099\u308f\u3063\u3066\u3044\u3066\u3001\u958b\u767a\u52b9\u7387\u304c\u98db\u8e8d\u7684\u306b\u5411\u4e0a\u3059\u308b\u3053\u3068\u9593\u9055\u3044\u306a\u3057\u3060\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002 \u305f\u3060\u3001\u305d\u3093\u306a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=420\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u30b7\u30f3\u30d7\u30eb\uff01Laravel5.6\u3067\u300c\u6a29\u9650\u3064\u304d\u300d\u30ed\u30b0\u30a4\u30f3\u3055\u305b\u308b\u65b9\u6cd5&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":429,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[58],"class_list":["post-420","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-58"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/420","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=420"}],"version-history":[{"count":2,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/420\/revisions"}],"predecessor-version":[{"id":5445,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/420\/revisions\/5445"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/429"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}