{"id":2650,"date":"2018-11-29T03:42:16","date_gmt":"2018-11-28T18:42:16","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=2650"},"modified":"2018-11-29T03:42:16","modified_gmt":"2018-11-28T18:42:16","slug":"%e3%81%9f%e3%81%a3%e3%81%9f3%e3%82%b9%e3%83%86%e3%83%83%e3%83%97%ef%bc%81laravel-gate%e3%81%a7%e5%ae%9f%e8%a1%8c%e6%a8%a9%e9%99%90%e3%82%92%e5%b0%8e%e5%85%a5%e3%81%99%e3%82%8b%e5%ae%9f%e4%be%8b","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=2650","title":{"rendered":"\u305f\u3063\u305f3\u30b9\u30c6\u30c3\u30d7\uff01Laravel Gate\u3067\u5b9f\u884c\u6a29\u9650\u3092\u5c0e\u5165\u3059\u308b\u5b9f\u4f8b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u4ee5\u524d\u516c\u958b\u3057\u305f\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=420\">\u30b7\u30f3\u30d7\u30eb\uff01Laravel\u3067\u300c\u6a29\u9650\u3064\u304d\u300d\u30ed\u30b0\u30a4\u30f3\u3055\u305b\u308b\u65b9\u6cd5<\/a>\u300d\u3067\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u3054\u3068\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u30da\u30fc\u30b8\u3092\u6c7a\u3081\u3001\u6a29\u9650\u304c\u7121\u3044\u5834\u5408\u306f\u5f37\u5236\u7684\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u3068\u3044\u3046\u30c6\u30af\u30cb\u30c3\u30af\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u4f7f\u3048\u3070\u3001\u3068\u3066\u3082\u30b7\u30f3\u30d7\u30eb\u306b\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\u3067\u30a2\u30af\u30bb\u30b9\u30da\u30fc\u30b8\u3092\u5206\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3001\u30a2\u30af\u30bb\u30b9\u3067\u306f\u306a\u304f\u5b9f\u884c\u6a29\u9650\u3068\u306a\u308b\u3068\u8a71\u306f\u5c11\u3057\u9055\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001<\/p>\n<ul>\n<li>\u793e\u9577\u3060\u3051\u304c\u30c7\u30fc\u30bf\u524a\u9664\u3067\u304d\u308b<\/li>\n<li>\u793e\u54e1\u306f\u5909\u66f4\u304c\u53ef\u80fd<\/li>\n<li>\u30a2\u30eb\u30d0\u30a4\u30c8\u306f\u898b\u308b\u3060\u3051<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u3088\u3046\u306a\u3001\u3088\u308a\u7d30\u304b\u3044\u6a29\u9650\u3092\u3064\u3051\u305f\u3044\u5834\u5408\u3067\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u305d\u3053\u306f\u4eba\u6c17\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306eLaravel\u3067\u3059\u3002<br \/>\n\u5b9f\u306f\u3001\u3053\u306e\u3088\u3046\u306a\u3088\u308a\u8907\u96d1\u306a\u5b9f\u884c\u6a29\u9650\u3092\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u308b<code>Laravel Gate<\/code>\u3068\u3044\u3046\u6a5f\u80fd\u3092\u6a19\u6e96\u642d\u8f09\u3057\u3066\u3044\u308b\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u3053\u3067\uff01<\/p>\n<p>\u4eca\u56de\u306f\u3053\u306e<code>Laravel Gate<\/code>\u3092\u4f7f\u3063\u3066\u5f79\u8077\u3054\u3068\u306b\u5b9f\u884c\u6a29\u9650\u3092\u3064\u3051\u308b\u5b9f\u4f8b\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<span style=\"font-size: 1rem;\">\u305c\u3072\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2594 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/23.png\" alt=\"\" width=\"182\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/23.png 182w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/23-171x300.png 171w\" sizes=\"auto, (max-width: 182px) 100vw, 182px\" \/><\/p>\n<p>\u203b \u958b\u767a\u74b0\u5883\uff1a Laravel 5.7<\/p>\n<h1>\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u4eca\u56de\u306f\u4ee5\u4e0b\uff13\u3064\u306e\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\u304c\u3042\u308b\u4f1a\u793e\u3084\u304a\u5e97\u306e\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3060\u3068\u8003\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<ul>\n<li>\u793e\u9577<\/li>\n<li>\u5f93\u696d\u54e1<\/li>\n<li>\u30a2\u30eb\u30d0\u30a4\u30c8<\/li>\n<\/ul>\n<p>\u305d\u3057\u3066\u3001\u3053\u308c\u3089\u306e\u30e6\u30fc\u30b6\u30fc\u304c\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u300c\u696d\u52d9\u9023\u7d61\u300d\u30da\u30fc\u30b8\u304c\u3042\u308b\u3068\u3057\u3066\u3001\u3053\u3053\u306b\u6b21\u306e\u5b9f\u884c\u6a29\u9650\u3092\u3064\u3051\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u793e\u9577\u3000\u30fb\u30fb\u30fb\u3000\u95b2\u89a7\u3001\u8ffd\u52a0\u3001\u5909\u66f4\u3001\u524a\u9664<\/li>\n<li>\u5f93\u696d\u54e1\u3000\u30fb\u30fb\u30fb\u3000\u95b2\u89a7\u3001\u8ffd\u52a0\u3001\u5909\u66f4<\/li>\n<li>\u30a2\u30eb\u30d0\u30a4\u30c8\u3000\u30fb\u30fb\u30fb\u3000\u95b2\u89a7<\/li>\n<\/ul>\n<p>\u3067\u306f\u5b9f\u969b\u306b\u958b\u767a\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<h1>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u3064\u304f\u308b<\/h1>\n<p>\u307e\u305a\u306f\u3001\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3067Laravel\u3067\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>php artisan make:auth<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001\u4f5c\u6210\u3055\u308c\u305f\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3<code>CreateUsersTable.php<\/code>\u3092\u958b\u3044\u3066<code>role<\/code>\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u8ffd\u52a0\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        <strong>$table-&gt;string('role'); \/\/ \u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7<\/strong>\r\n        $table-&gt;timestamp('email_verified_at')-&gt;nullable();\r\n        $table-&gt;string('password');\r\n        $table-&gt;rememberToken();\r\n        $table-&gt;timestamps();\r\n    });\r\n}<\/pre>\n<p>\u7d9a\u3044\u3066\u3001\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3059\u308b<code>UsersTableSeeder<\/code>\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<pre>php artisan make:seed UsersTableSeeder<\/pre>\n<p>\u4f5c\u6210\u3055\u308c\u305f<code>UsersTableSeeder.php<\/code>\u3092\u958b\u3044\u3066\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre>public function run()\r\n{\r\n    $users = [\r\n        [\r\n            'name' =&gt; '\u793e\u9577',\r\n            'role' =&gt; 'president',\r\n            'email' =&gt; 'president@example.com'\r\n        ],\r\n        [\r\n            'name' =&gt; '\u5f93\u696d\u54e1',\r\n            'role' =&gt; 'employee',\r\n            'email' =&gt; 'employee@example.com'\r\n        ],\r\n        [\r\n            'name' =&gt; '\u30a2\u30eb\u30d0\u30a4\u30c8',\r\n            'role' =&gt; 'part_timer',\r\n            'email' =&gt; 'part_timer@example.com'\r\n        ]\r\n    ];\r\n\r\n    foreach ($users as $user) {\r\n\r\n        \\App\\User::create([\r\n            'name' =&gt; $user['name'],\r\n            'email' =&gt; $user['email'],\r\n            'role' =&gt; $user['role'],\r\n            'password' =&gt; bcrypt('xxxxxxxx')\r\n        ]);\r\n\r\n    }\r\n}<\/pre>\n<p>\u6b21\u306b\u5fd8\u308c\u3066\u306f\u3044\u3051\u306a\u3044\u306e\u304c\u3001\u3053\u306e<code>UsersTableSeeder<\/code>\u3092\u6709\u52b9\u306b\u3059\u308b\u305f\u3081\u306e<code>DatabaseSeeder.php<\/code>\u3078\u306e\u767b\u9332\u3067\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\r\nuse Illuminate\\Database\\Seeder;\r\n\r\nclass DatabaseSeeder extends Seeder\r\n{\r\n    public function run()\r\n    {\r\n        <strong>$this-&gt;call(UsersTableSeeder::class);<\/strong>\r\n    }\r\n}<\/pre>\n<p>\u3067\u306f\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>php artisan migrate:fresh --seed<\/pre>\n<p>DB\u30c6\u30fc\u30d6\u30eb\u3053\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2651\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_gate_1.png\" alt=\"\" width=\"545\" height=\"316\" \/><\/p>\n<h1>Laravel Gate\u306e\u5b9f\u884c\u6a29\u9650\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306fLaravel Gate\u3092\u4f7f\u3063\u3066\u300c\u3084\u308a\u305f\u3044\u3053\u3068\u300d\u306b\u66f8\u3044\u305f\u6b21\u306e\u6a29\u9650\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<ul>\n<li>\u793e\u9577\u3000\u30fb\u30fb\u30fb\u3000\u95b2\u89a7\u3001\u8ffd\u52a0\u3001\u5909\u66f4\u3001\u524a\u9664<\/li>\n<li>\u5f93\u696d\u54e1\u3000\u30fb\u30fb\u30fb\u3000\u95b2\u89a7\u3001\u8ffd\u52a0\u3001\u5909\u66f4<\/li>\n<li>\u30a2\u30eb\u30d0\u30a4\u30c8\u3000\u30fb\u30fb\u30fb\u3000\u95b2\u89a7<\/li>\n<\/ul>\n<p>\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u306e\u306f\u3001<code>app\/Providers\/AuthServiceProvider.php<\/code>\u306e<code>boot()<\/code>\u5185\u3067\u3059\u3067\u3059\u3002<\/p>\n<h2>Policy\u3092\u3064\u304f\u308b<\/h2>\n<p>\u6a29\u9650\u304c\u5c11\u306a\u3051\u308c\u3070\u3001\u305d\u306e\u307e\u307e\u6b21\u306e\u3088\u3046\u306b<code>AuthServiceProvider.php<\/code>\u306b\u76f4\u66f8\u304d\u3057\u3066\u3082\u69cb\u3044\u307e\u305b\u3093\u3002<\/p>\n<pre>public function boot()\r\n{\r\n    $this-&gt;registerPolicies();\r\n\r\n    <strong>Gate::define('delete-announcement', function ($user) {<\/strong>\r\n\r\n<strong>        return ($user-&gt;role == 'president'); \/\/ \u793e\u9577\u3060\u3051\u524a\u9664OK<\/strong>\r\n\r\n<strong>    });<\/strong>\r\n}<\/pre>\n<p>\u305f\u3060\u3001Laravel\u306b\u306f\u4fdd\u5b88\u7ba1\u7406\u3057\u3084\u3059\u3044\u3088\u3046\u306b\u5b9f\u884c\u6a29\u9650\u3092\u7ba1\u7406\u3059\u308b<code>Policy<\/code>\u3068\u3044\u3046\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u4eca\u56de\u306f\u3053\u3061\u3089\u3067\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>php artisan make:policy AnnouncementPolicy<\/pre>\n<p>\u3059\u308b\u3068\u3001<code>app\/Policies\/AnnoucementPolicy.php<\/code>\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Policies;\r\n\r\nuse App\\User;\r\nuse Illuminate\\Auth\\Access\\HandlesAuthorization;\r\n\r\nclass AnnouncementPolicy\r\n{\r\n    use HandlesAuthorization;\r\n\r\n    \/* \u95b2\u89a7 *\/\r\n    public function view(User $user)\r\n    {\r\n        $user_types = [\r\n            'president', \/\/ \u793e\u9577\r\n            'employee',  \/\/ \u5f93\u696d\u54e1\r\n            'part_timer' \/\/ \u30a2\u30eb\u30d0\u30a4\u30c8\r\n        ];\r\n        return (in_array($user-&gt;role, $user_types));\r\n    }\r\n\r\n    \/* \u8ffd\u52a0 *\/\r\n    public function create(User $user)\r\n    {\r\n        $user_types = [\r\n            'president', \/\/ \u793e\u9577\r\n            'employee'   \/\/ \u5f93\u696d\u54e1\r\n        ];\r\n        return (in_array($user-&gt;role, $user_types));\r\n    }\r\n\r\n    \/* \u5909\u66f4 *\/\r\n    public function update(User $user)\r\n    {\r\n        $user_types = [\r\n            'president', \/\/ \u793e\u9577\r\n            'employee'   \/\/ \u5f93\u696d\u54e1\r\n        ];\r\n        return (in_array($user-&gt;role, $user_types));\r\n    }\r\n\r\n    \/* \u524a\u9664 *\/\r\n    public function delete(User $user)\r\n    {\r\n        return ($user-&gt;role == 'president'); \/\/ \u793e\u9577\u3060\u3051OK\r\n    }\r\n}<\/pre>\n<p>\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u3001\u305d\u308c\u305e\u308c<code>$user-&gt;role<\/code>\u306e\u4e2d\u8eab\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066<code>return<\/code>\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001<code>AuthServiceProvider.php<\/code>\u3067\u3001<code>AnnouncementPolicy<\/code>\u3092\u767b\u9332\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>public function boot()\r\n{\r\n    $this-&gt;registerPolicies();\r\n\r\n    <strong>Gate::resource('announcements', 'App\\Policies\\AnnouncementPolicy');<\/strong>\r\n}<\/pre>\n<p>\u3061\u306a\u307f\u306b<code>Gate::resource()<\/code>\u306f\u3001\u4ee5\u4e0b\uff14\u3064\u306e\u6a29\u9650\u3092\u4e00\u6c17\u306b\u4f5c\u3063\u3066\u304f\u308c\u308b\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u66f8\u304d\u65b9\u3067\u3059\u3002<\/p>\n<ul>\n<li>view<\/li>\n<li>create<\/li>\n<li>update<\/li>\n<li>delete<\/li>\n<\/ul>\n<p>\u305d\u306e\u305f\u3081\u3001\u4e0a\u306e\u30b3\u30fc\u30c9\u306f\u6b21\u306e\u30b3\u30fc\u30c9\u3068\u540c\u3058\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u304a\u597d\u307f\u3067\u4f7f\u3044\u5206\u3051\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>Gate::define('announcements.view', 'App\\Policies\\AnnouncementPolicy@view');\r\nGate::define('announcements.create', 'App\\Policies\\AnnouncementPolicy@create');\r\nGate::define('announcements.update', 'App\\Policies\\AnnouncementPolicy@update');\r\nGate::define('announcements.delete', 'App\\Policies\\AnnouncementPolicy@delete');<\/pre>\n<h1>\u5b9f\u884c\u6a29\u9650\u3092\u8a2d\u7f6e\u3059\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u4f5c\u6210\u3057\u305f\u6a29\u9650\u3092\u8a2d\u7f6e\u3059\u308b\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>$user = auth()-&gt;loginUsingId(1);\r\n\r\n\/* \u95b2\u89a7 *\/\r\nif(Gate::allows('announcements.view', $user)) {\r\n\r\n    echo '\u95b2\u89a7\u3067\u304d\u307e\u3059\u3002';\r\n\r\n} else {\r\n\r\n    echo '\u95b2\u89a7\u3067\u304d\u307e\u305b\u3093\uff01';\r\n\r\n}\r\n\r\n\/* \u8ffd\u52a0 *\/\r\nif(Gate::allows('announcements.create', $user)) {\r\n\r\n    echo '\u8ffd\u52a0\u3067\u304d\u307e\u3059\u3002';\r\n\r\n} else {\r\n\r\n    echo '\u8ffd\u52a0\u3067\u304d\u307e\u305b\u3093\uff01';\r\n\r\n}\r\n\r\n\/* \u5909\u66f4 *\/\r\nif(Gate::allows('announcements.update', $user)) {\r\n\r\n    echo '\u5909\u66f4\u3067\u304d\u307e\u3059\u3002';\r\n\r\n} else {\r\n\r\n    echo '\u5909\u66f4\u3067\u304d\u307e\u305b\u3093\uff01';\r\n\r\n}\r\n\r\n\/* \u524a\u9664 *\/\r\nif(Gate::allows('announcements.delete', $user)) {\r\n\r\n    echo '\u524a\u9664\u3067\u304d\u307e\u3059\u3002';\r\n\r\n} else {\r\n\r\n    echo '\u524a\u9664\u3067\u304d\u307e\u305b\u3093\uff01';\r\n\r\n}<\/pre>\n<p>\u307e\u305a\uff11\u884c\u76ee\u306f\u30e6\u30fc\u30b6\u30fc\uff08\u3053\u3053\u3067\u306f\u793e\u9577\u30e6\u30fc\u30b6\u30fc\uff09\u3092\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001<code>Gate::allows()<\/code>\u3092\u4f7f\u3063\u3066\u6a29\u9650\u304c\u300c\u3042\u308b\u4eba\u3060\u3051\u300d\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u5206\u5c90\u3055\u305b\u3066\u3044\u307e\u3059\u3002\u3082\u3057\u3001\u9006\u306b\u6a29\u9650\u304c\u300c\u306a\u3044\u4eba\u3060\u3051\u300d\u3092\u30c1\u30a7\u30c3\u30af\u3057\u305f\u3044\u5834\u5408\u306f<code>Gate::denies()<\/code>\u3092\u4f7f\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u5b9f\u884c\u7d50\u679c<\/h2>\n<p>\u3067\u306f\u5b9f\u969b\u306b\u3069\u306e\u3088\u3046\u306b\u306a\u308b\u304b\u5404\u30e6\u30fc\u30b6\u30fc\u306e\u5b9f\u884c\u7d50\u679c\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u793e\u9577\u306e\u5834\u5408<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2655\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_gate_2.png\" alt=\"\" width=\"406\" height=\"33\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_gate_2.png 406w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_gate_2-300x24.png 300w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/p>\n<h3>\u5f93\u696d\u54e1\u306e\u5834\u5408<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_gate_3.png\" alt=\"\" width=\"419\" height=\"31\" \/><\/p>\n<h3>\u30a2\u30eb\u30d0\u30a4\u30c8\u306e\u5834\u5408<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_gate_4.png\" alt=\"\" width=\"448\" height=\"33\" \/><\/p>\n<h2>Blade\u3067\u6a29\u9650\u304c\u3042\u308b\u4eba\u306b\u3060\u3051\u30ea\u30f3\u30af\u3092\u8868\u793a\u3059\u308b<\/h2>\n<p><code>Laravel Gate<\/code>\u306f\u901a\u5e38\u306ePHP\u30b3\u30fc\u30c9\u3060\u3051\u3067\u306a\u304f\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30fb\u30a8\u30f3\u30b8\u30f3<code>Blade<\/code>\u306e\u4e2d\u3067\u3082\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u300c\u696d\u52d9\u9023\u7d61\u306e\u6a29\u9650\u304c\u3042\u308b\u4eba\u306b\u3060\u3051\u30ea\u30f3\u30af\u3092\u8868\u793a\u3059\u308b\u300d\u3068\u3044\u3063\u305f\u4f7f\u3044\u65b9\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>&lt;!-- \u696d\u52d9\u9023\u7d61 --&gt;\r\n<strong>@can<\/strong>('announcements.view', auth()-&gt;user())\r\n    &lt;a href=\"\/announcements\"&gt;\u696d\u52d9\u9023\u7d61&lt;\/a&gt;\r\n<strong>@endcan<\/strong><\/pre>\n<p>\u4f7f\u3044\u65b9\u306f\u5148\u307b\u3069\u306e<code>allows()<\/code>\u3068\u307b\u307c\u540c\u3058\u3067<code>@can<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002\uff08\u9006\u306f<code>@cannot<\/code>\uff09<\/p>\n<p>\u3053\u308c\u3092Laravel\u306b\u59cb\u3081\u304b\u3089\u7528\u610f\u3055\u308c\u3066\u3044\u308b<code>welcom.blade.php<\/code>\u3067\u5b9f\u884c\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u306a\u3044\u72b6\u614b\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2658\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_gate_5.png\" alt=\"\" width=\"220\" height=\"60\" \/><\/p>\n<p>\u4f55\u3082\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<p>\u6b21\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u8868\u793a\u3057\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2659\" style=\"border: 1px solid #ccc;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/laravel_gate_6.png\" alt=\"\" width=\"205\" height=\"59\" \/><\/p>\n<p>\u696d\u52d9\u9023\u7d61\u3068\u3044\u3046\u30ea\u30f3\u30af\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<br \/>\n\u3082\u3061\u308d\u3093\u3001\u6a29\u9650\u3092\u3082\u3063\u3066\u3044\u306a\u3051\u308c\u3070\u3001\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u3066\u3082\u8868\u793a\u3055\u308c\u306a\u3044\u30d1\u30bf\u30fc\u30f3\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\uff01<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Laravel Gate<\/code>\u3092\u4f7f\u3063\u3066\u5b9f\u884c\u6a29\u9650\u3092\u7ba1\u7406\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u7279\u306b\u4f1a\u793e\u7d44\u7e54\u306e\u30b5\u30a4\u30c8\u306a\u3069\u3001\u30e6\u30fc\u30b6\u30fc\u30bf\u30a4\u30d7\u304c\u591a\u3044\u5834\u5408\u306b\u91cd\u5b9d\u3059\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002\u307e\u305f\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u4eee\u767b\u9332\u3057\u304b\u3057\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u6295\u7a3f\u3092\u62d2\u5426\u3057\u305f\u308a\u3001\u6295\u7a3f\u3057\u305f\u672c\u4eba\u3060\u3051\u5909\u66f4\uff0f\u524a\u9664\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3068\u3044\u3046\u8a2d\u5b9a\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u5b9f\u884c\u6a29\u9650\u3092<code>Policy<\/code>\u3068\u3057\u3066\u5206\u5272\u7ba1\u7406\u3057\u3066\u304a\u3051\u3070\u4ee5\u524d\u4f7f\u3063\u305f\u3082\u306e\u3092\u518d\u5229\u7528\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u305d\u306e\u5f8c\u306e\u958b\u767a\u52b9\u7387\u304c\u30b0\u30f3\u3063\u3068\u3042\u304c\u308b\u3068\u3044\u3046\u30e1\u30ea\u30c3\u30c8\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u6d3b\u7528\u3057\u3066\u307f\u3066\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1419 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/10.png\" alt=\"\" width=\"306\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/10.png 306w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/10\/10-287x300.png 287w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u4ee5\u524d\u516c\u958b\u3057\u305f\u300c\u30b7\u30f3\u30d7\u30eb\uff01Laravel\u3067\u300c\u6a29\u9650\u3064\u304d\u300d\u30ed\u30b0\u30a4\u30f3\u3055\u305b\u308b\u65b9\u6cd5\u300d\u3067\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u3054\u3068\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u30da\u30fc\u30b8\u3092\u6c7a\u3081\u3001\u6a29\u9650\u304c\u7121\u3044\u5834\u5408\u306f\u5f37\u5236\u7684\u306b\u30ea\u30c0\u30a4 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=2650\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u305f\u3063\u305f3\u30b9\u30c6\u30c3\u30d7\uff01Laravel Gate\u3067\u5b9f\u884c\u6a29\u9650\u3092\u5c0e\u5165\u3059\u308b\u5b9f\u4f8b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":2662,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[122],"class_list":["post-2650","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-122"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2650","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=2650"}],"version-history":[{"count":5,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2650\/revisions"}],"predecessor-version":[{"id":2663,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/2650\/revisions\/2663"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/2662"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}