{"id":24917,"date":"2024-11-21T15:24:44","date_gmt":"2024-11-21T07:24:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/24917\/"},"modified":"2024-11-21T15:24:44","modified_gmt":"2024-11-21T07:24:44","slug":"laravel%e6%9d%83%e9%99%90%e5%8a%9f%e8%83%bd%e7%9a%84%e6%9c%80%e6%96%b0%e5%8f%91%e5%b1%95%ef%bc%9a%e5%a6%82%e4%bd%95%e5%ba%94%e5%af%b9%e5%a4%9a%e7%a7%9f%e6%88%b7%e7%8e%af%e5%a2%83%e4%b8%8b%e7%9a%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/24917\/","title":{"rendered":"Laravel\u6743\u9650\u529f\u80fd\u7684\u6700\u65b0\u53d1\u5c55\uff1a\u5982\u4f55\u5e94\u5bf9\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169907357669887.jpg\" class=\"aligncenter\" title=\"Laravel\u6743\u9650\u529f\u80fd\u7684\u6700\u65b0\u53d1\u5c55\uff1a\u5982\u4f55\u5e94\u5bf9\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\u63d2\u56fe\" alt=\"Laravel\u6743\u9650\u529f\u80fd\u7684\u6700\u65b0\u53d1\u5c55\uff1a\u5982\u4f55\u5e94\u5bf9\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\u63d2\u56fe\" \/><\/p>\n<p>Laravel\u6743\u9650\u529f\u80fd\u7684\u6700\u65b0\u53d1\u5c55\uff1a\u5982\u4f55\u5e94\u5bf9\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\uff0c\u9700\u8981\u5177\u4f53\u4ee3\u7801\u793a\u4f8b<\/p>\n<p>\u8fd1\u5e74\u6765\uff0c\u968f\u7740\u4e91\u8ba1\u7b97\u548c\u8f6f\u4ef6\u5373\u670d\u52a1\uff08SaaS\uff09\u7684\u5174\u8d77\uff0c\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\u6210\u4e3a\u8f6f\u4ef6\u5f00\u53d1\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u6311\u6218\u3002\u5728\u8fd9\u79cd\u73af\u5883\u4e2d\uff0c\u591a\u4e2a\u7528\u6237\u6216\u7ec4\u7ec7\u5171\u4eab\u540c\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u6bcf\u4e2a\u7528\u6237\u6216\u7ec4\u7ec7\u53ea\u80fd\u8bbf\u95ee\u81ea\u5df1\u62e5\u6709\u7684\u6570\u636e\u548c\u529f\u80fd\u3002\u5728\u8fd9\u6837\u7684\u573a\u666f\u4e0b\uff0c\u5982\u4f55\u786e\u4fdd\u7528\u6237\u53ea\u80fd\u8bbf\u95ee\u4ed6\u4eec\u6709\u6743\u9650\u7684\u8d44\u6e90\uff0c\u6210\u4e3a\u4e86\u4e00\u4e2a\u5fc5\u987b\u8981\u89e3\u51b3\u7684\u95ee\u9898\u3002<\/p>\n<p>Laravel\u4f5c\u4e3a\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684PHP\u5f00\u53d1\u6846\u67b6\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6743\u9650\u7ba1\u7406\u529f\u80fd\u3002\u6700\u65b0\u7684Laravel\u7248\u672c\u8fdb\u4e00\u6b65\u5b8c\u5584\u4e86\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\u529f\u80fd\uff0c\u4f7f\u5176\u66f4\u6613\u4e8e\u4f7f\u7528\u548c\u914d\u7f6e\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Laravel\u6765\u5e94\u5bf9\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\uff0c\u5e76\u63d0\u4f9b\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u5728Laravel\u4e2d\uff0c\u6743\u9650\u901a\u5e38\u901a\u8fc7\u89d2\u8272\u548c\u6743\u9650\u4e24\u4e2a\u6982\u5ff5\u6765\u5904\u7406\u3002\u89d2\u8272\u5b9a\u4e49\u4e86\u7528\u6237\u7684\u8eab\u4efd\u6216\u89d2\u8272\uff0c\u800c\u6743\u9650\u5b9a\u4e49\u4e86\u7528\u6237\u53ef\u4ee5\u6267\u884c\u7684\u7279\u5b9a\u64cd\u4f5c\u3002\u901a\u8fc7\u5c06\u89d2\u8272\u548c\u6743\u9650\u5173\u8054\u8d77\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u7ba1\u7406\u7528\u6237\u7684\u6743\u9650\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728\u6570\u636e\u5e93\u4e2d\u5efa\u7acb\u76f8\u5e94\u7684\u8868\u6765\u5b58\u50a8\u89d2\u8272\u548c\u6743\u9650\u7684\u4fe1\u606f\u3002\u5728Laravel\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u8fc1\u79fb\u6765\u521b\u5efa\u8fd9\u4e9b\u8868\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u521b\u5efa\u89d2\u8272\u548c\u6743\u9650\u8868\u7684\u8fc1\u79fb\u793a\u4f8b\uff1a<\/p>\n<pre>use IlluminateDatabaseMigrationsMigration;\nuse IlluminateDatabaseSchemaBlueprint;\nuse IlluminateSupportFacadesSchema;\n\nclass CreateRolesAndPermissionsTable extends Migration\n{\n    public function up()\n    {\n        Schema::create('roles', function (Blueprint $table) {\n            $table-&amp;gt;id();\n            $table-&amp;gt;string('name')-&amp;gt;unique();\n            $table-&amp;gt;timestamps();\n        });\n\n        Schema::create('permissions', function (Blueprint $table) {\n            $table-&amp;gt;id();\n            $table-&amp;gt;string('name')-&amp;gt;unique();\n            $table-&amp;gt;timestamps();\n        });\n\n        Schema::create('role_permission', function (Blueprint $table) {\n            $table-&amp;gt;id();\n            $table-&amp;gt;unsignedBigInteger('role_id');\n            $table-&amp;gt;unsignedBigInteger('permission_id');\n            $table-&amp;gt;timestamps();\n\n            $table-&amp;gt;foreign('role_id')-&amp;gt;references('id')-&amp;gt;on('roles')-&amp;gt;onDelete('cascade');\n            $table-&amp;gt;foreign('permission_id')-&amp;gt;references('id')-&amp;gt;on('permissions')-&amp;gt;onDelete('cascade');\n        });\n    }\n\n    public function down()\n    {\n        Schema::dropIfExists('role_permission');\n        Schema::dropIfExists('roles');\n        Schema::dropIfExists('permissions');\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u8fd9\u4e2a\u8fc1\u79fb\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86roles\u8868\u3001permissions\u8868\u548crole_permission\u8868\u6765\u5b58\u50a8\u89d2\u8272\u548c\u6743\u9650\u7684\u4fe1\u606f\u3002role_permission\u8868\u662f\u89d2\u8272\u548c\u6743\u9650\u7684\u5173\u8054\u8868\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Laravel\u7684\u8ba4\u8bc1\u548c\u6388\u6743\u7cfb\u7edf\u6765\u7ba1\u7406\u7528\u6237\u7684\u89d2\u8272\u548c\u6743\u9650\u3002\u9996\u5148\uff0c\u5728User\u6a21\u578b\u4e2d\u5b9a\u4e49\u7528\u6237\u4e0e\u89d2\u8272\u7684\u5173\u8054\u5173\u7cfb\uff1a<\/p>\n<pre>use IlluminateFoundationAuthUser as Authenticatable;\nuse IlluminateDatabaseEloquentRelationsBelongsToMany;\n\nclass User extends Authenticatable\n{\n    public function roles(): BelongsToMany\n    {\n        return $this-&amp;gt;belongsToMany(Role::class);\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728Role\u6a21\u578b\u4e2d\u5b9a\u4e49\u89d2\u8272\u4e0e\u6743\u9650\u7684\u5173\u8054\u5173\u7cfb\uff1a<\/p>\n<pre>use IlluminateDatabaseEloquentModel;\nuse IlluminateDatabaseEloquentRelationsBelongsToMany;\n\nclass Role extends Model\n{\n    public function permissions(): BelongsToMany\n    {\n        return $this-&amp;gt;belongsToMany(Permission::class);\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7136\u540e\uff0c\u5728\u9700\u8981\u8fdb\u884c\u6743\u9650\u9a8c\u8bc1\u7684\u5730\u65b9\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Laravel\u7684\u6388\u6743\u7cfb\u7edf\u6765\u68c0\u67e5\u7528\u6237\u662f\u5426\u6709\u6267\u884c\u67d0\u4e2a\u64cd\u4f5c\u7684\u6743\u9650\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u68c0\u67e5\u7528\u6237\u662f\u5426\u6709\u521b\u5efa\u65b0\u7528\u6237\u7684\u6743\u9650\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>use IlluminateSupportFacadesGate;\n\nif (Gate::allows('create-user')) {\n    \/\/ \u7528\u6237\u6709\u521b\u5efa\u65b0\u7528\u6237\u7684\u6743\u9650\n} else {\n    \/\/ \u7528\u6237\u6ca1\u6709\u6743\u9650\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Gate::allows()\u65b9\u6cd5\u6765\u5224\u65ad\u7528\u6237\u662f\u5426\u6709\u6267\u884ccreate-user\u64cd\u4f5c\u7684\u6743\u9650\u3002\u5982\u679c\u7528\u6237\u6709\u6743\u9650\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\uff1b\u5426\u5219\uff0c\u6211\u4eec\u53ef\u4ee5\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38\u6216\u8005\u663e\u793a\u4e00\u4e2a\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u9700\u8981\u4e3a\u4e0d\u540c\u7684\u79df\u6237\u5206\u914d\u89d2\u8272\u548c\u6743\u9650\u3002\u5728\u591a\u79df\u6237\u73af\u5883\u4e0b\uff0c\u6bcf\u4e2a\u79df\u6237\u53ef\u80fd\u6709\u81ea\u5df1\u72ec\u7acb\u7684\u89d2\u8272\u548c\u6743\u9650\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Laravel\u63d0\u4f9b\u7684\u4e8b\u4ef6\u548c\u8ba2\u9605\u8005\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4e3a\u65b0\u5efa\u79df\u6237\u5206\u914d\u89d2\u8272\u548c\u6743\u9650\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>use AppEventsTenantCreated;\nuse AppListenersAssignDefaultRolesAndPermissionsToTenant;\n\nEvent::listen(\n    TenantCreated::class,\n    AssignDefaultRolesAndPermissionsToTenant::class\n);\n\nclass AssignDefaultRolesAndPermissionsToTenant\n{\n    public function handle(TenantCreated $event)\n    {\n        $tenant = $event-&amp;gt;tenant;\n\n        \/\/ \u4e3a\u79df\u6237\u5206\u914d\u9ed8\u8ba4\u89d2\u8272\u548c\u6743\u9650\n        $defaultRole = Role::where('name', 'tenant')-&amp;gt;first();\n        $defaultPermission = Permission::where('name', 'create-resource')-&amp;gt;first();\n        $tenant-&amp;gt;roles()-&amp;gt;attach($defaultRole);\n        $defaultRole-&amp;gt;permissions()-&amp;gt;attach($defaultPermission);\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2aTenantCreated\u4e8b\u4ef6\u548c\u4e00\u4e2aAssignDefaultRolesAndPermissionsToTenant\u8ba2\u9605\u8005\u3002\u5f53\u65b0\u5efa\u4e00\u4e2a\u79df\u6237\u65f6\uff0c\u7cfb\u7edf\u4f1a\u89e6\u53d1TenantCreated\u4e8b\u4ef6\uff0c\u7136\u540eAssignDefaultRolesAndPermissionsToTenant\u8ba2\u9605\u8005\u4f1a\u7ed9\u65b0\u5efa\u7684\u79df\u6237\u5206\u914d\u9ed8\u8ba4\u7684\u89d2\u8272\u548c\u6743\u9650\u3002<\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u7684\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u5728Laravel\u4e2d\u5b9e\u73b0\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\u3002Laravel\u7684\u6743\u9650\u529f\u80fd\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u914d\u7f6e\u9009\u9879\u548c\u6613\u4e8e\u4f7f\u7528\u7684\u63a5\u53e3\uff0c\u4f7f\u5f97\u5728\u591a\u79df\u6237\u73af\u5883\u4e0b\u5904\u7406\u6743\u9650\u53d8\u5f97\u66f4\u52a0\u7b80\u5355\u3002\u540c\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u7075\u6d3b\u5730\u8c03\u6574\u548c\u6269\u5c55\u6743\u9650\u529f\u80fd\uff0c\u4ee5\u9002\u5e94\u4e0d\u540c\u7684\u4e1a\u52a1\u573a\u666f\u3002<\/p>\n<p>\u603b\u7ed3\u8d77\u6765\uff0cLaravel\u5728\u6700\u65b0\u7248\u672c\u4e2d\u8fdb\u4e00\u6b65\u5b8c\u5584\u4e86\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\u529f\u80fd\u3002\u901a\u8fc7\u5efa\u7acb\u89d2\u8272\u548c\u6743\u9650\u8868\u3001\u5b9a\u4e49\u6a21\u578b\u5173\u8054\u5173\u7cfb\u3001\u4f7f\u7528\u8ba4\u8bc1\u548c\u6388\u6743\u7cfb\u7edf\u4ee5\u53ca\u4f7f\u7528\u4e8b\u4ef6\u548c\u8ba2\u9605\u8005\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5b9e\u73b0\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\u3002\u5e0c\u671b\u4ee5\u4e0a\u7684\u4ee3\u7801\u793a\u4f8b\u80fd\u591f\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528Laravel\u7684\u6743\u9650\u529f\u80fd\uff0c\u4f7f\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u5728\u591a\u79df\u6237\u73af\u5883\u4e0b\u66f4\u52a0\u5b89\u5168\u548c\u53ef\u9760\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fLaravel\u6743\u9650\u529f\u80fd\u7684\u6700\u65b0\u53d1\u5c55\uff1a\u5982\u4f55\u5e94\u5bf9\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel\u6743\u9650\u529f\u80fd\u7684\u6700\u65b0\u53d1\u5c55\uff1a\u5982\u4f55\u5e94\u5bf9\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\uff0c\u9700\u8981\u5177\u4f53\u4ee3\u7801\u793a\u4f8b \u8fd1\u5e74\u6765\uff0c\u968f\u7740\u4e91\u8ba1\u7b97\u548c\u8f6f\u4ef6\u5373\u670d\u52a1\uff08SaaS\uff09\u7684\u5174\u8d77\uff0c\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\u6210\u4e3a\u8f6f\u4ef6\u5f00\u53d1\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u6311\u6218\u3002\u5728\u8fd9\u79cd\u73af\u5883\u4e2d\uff0c\u591a\u4e2a\u7528\u6237\u6216\u7ec4\u7ec7\u5171\u4eab\u540c\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u6bcf\u4e2a\u7528\u6237\u6216\u7ec4\u7ec7\u53ea\u80fd\u8bbf\u95ee\u81ea\u5df1\u62e5\u6709\u7684\u6570\u636e\u548c\u529f\u80fd\u3002\u5728\u8fd9\u6837\u7684\u573a\u666f\u4e0b\uff0c\u5982\u4f55\u786e\u4fdd\u7528\u6237\u53ea\u80fd\u8bbf\u95ee\u4ed6\u4eec\u6709\u6743\u9650\u7684\u8d44\u6e90\uff0c\u6210\u4e3a\u4e86\u4e00\u4e2a\u5fc5\u987b\u8981\u89e3\u51b3\u7684\u95ee\u9898\u3002 Laravel\u4f5c\u4e3a\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u7684PHP\u5f00\u53d1\u6846\u67b6\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6743\u9650\u7ba1\u7406\u529f\u80fd\u3002\u6700\u65b0\u7684Laravel\u7248\u672c\u8fdb\u4e00\u6b65\u5b8c\u5584\u4e86\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\u529f\u80fd\uff0c\u4f7f\u5176\u66f4\u6613\u4e8e\u4f7f\u7528\u548c\u914d\u7f6e\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Laravel\u6765\u5e94\u5bf9\u591a\u79df\u6237\u73af\u5883\u4e0b\u7684\u6743\u9650\u7ba1\u7406\uff0c\u5e76\u63d0\u4f9b\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u5728Laravel\u4e2d\uff0c\u6743\u9650\u901a\u5e38\u901a\u8fc7\u89d2\u8272\u548c\u6743\u9650\u4e24\u4e2a\u6982\u5ff5\u6765\u5904\u7406\u3002\u89d2\u8272\u5b9a\u4e49\u4e86\u7528\u6237\u7684\u8eab\u4efd\u6216\u89d2\u8272\uff0c\u800c\u6743\u9650\u5b9a\u4e49\u4e86\u7528\u6237\u53ef\u4ee5\u6267\u884c\u7684\u7279\u5b9a\u64cd\u4f5c\u3002\u901a\u8fc7\u5c06\u89d2\u8272\u548c\u6743\u9650\u5173\u8054\u8d77\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u7ba1\u7406\u7528\u6237\u7684\u6743\u9650\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728\u6570\u636e\u5e93\u4e2d\u5efa\u7acb\u76f8\u5e94\u7684\u8868\u6765\u5b58\u50a8\u89d2\u8272\u548c\u6743\u9650\u7684\u4fe1\u606f\u3002\u5728Laravel\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u8fc1\u79fb\u6765\u521b\u5efa\u8fd9\u4e9b\u8868\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u521b\u5efa\u89d2\u8272\u548c\u6743\u9650\u8868\u7684\u8fc1\u79fb\u793a\u4f8b\uff1a use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; class CreateRolesAndPermissionsTable extends Migration { public function up() { Schema::create(&#8216;roles&#8217;, function (Blueprint $table) { $table-&amp;gt;id(); $table-&amp;gt;string(&#8216;name&#8217;)-&amp;gt;unique(); $table-&amp;gt;timestamps(); }); Schema::create(&#8216;permissions&#8217;, function (Blueprint $table) { $table-&amp;gt;id(); $table-&amp;gt;string(&#8216;name&#8217;)-&amp;gt;unique(); $table-&amp;gt;timestamps(); }); Schema::create(&#8216;role_permission&#8217;, function (Blueprint $table) { $table-&amp;gt;id(); $table-&amp;gt;unsignedBigInteger(&#8216;role_id&#8217;); $table-&amp;gt;unsignedBigInteger(&#8216;permission_id&#8217;); $table-&amp;gt;timestamps(); $table-&amp;gt;foreign(&#8216;role_id&#8217;)-&amp;gt;references(&#8216;id&#8217;)-&amp;gt;on(&#8216;roles&#8217;)-&amp;gt;onDelete(&#8216;cascade&#8217;); $table-&amp;gt;foreign(&#8216;permission_id&#8217;)-&amp;gt;references(&#8216;id&#8217;)-&amp;gt;on(&#8216;permissions&#8217;)-&amp;gt;onDelete(&#8216;cascade&#8217;); }); } public function down() { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-24917","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24917","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=24917"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24917\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=24917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=24917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=24917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}