[英]Laravel - How to add extra column to Laravel Spatie Permission
In my Laravel-8 project, I am using Spatie-Permission.在我的 Laravel-8 项目中,我使用的是 Spatie-Permission。 I want to add extra column, company_id to the Spatie Role table.我想在 Spatie Role 表中添加额外的列 company_id。 In the migration, I did this:在迁移中,我这样做了:
php artisan make:migration add_company_column_to_role_tables
Also, in the config/permission:此外,在配置/权限中:
//'permission' => Spatie\Permission\Models\Permission::class,
'permission' => App\Models\Permission::class,
//'role' => Spatie\Permission\Models\Role::class,
'role' => App\Models\Role::class,
I want each company to create its roles, but the permissions remain the same.我希望每个公司都创建自己的角色,但权限保持不变。 What else do I need to do in order to make it work?我还需要做什么才能使其正常工作?
Thanks谢谢
I recently face this.我最近面对这个。 I needed to have an additional display_name for my permissions.我需要一个额外的display_name来获得我的权限。 People on the spatie github repo said it was better to use Laravel translations in the next fashion: spatie github repo 上的人说,最好在下一个方式中使用 Laravel 翻译:
__('your string permission')
But I found that not that suitable.但我发现那不太合适。 So I did this:所以我这样做了:
Added a migration: php artisan make:migration addCustomColumnsToPermissionsTable添加了迁移: php artisan make:migration addCustomColumnsToPermissionsTable
Then, added the following:然后,添加以下内容:
public function up() { Schema::table('permissions', function (Blueprint $table) { $table->string('display_name')->after('name'); });公共 function up() { Schema::table('permissions', function (Blueprint $table) { $table->string('display_name')->after('name'); }); } }
public function down() { Schema::table('permissions', function (Blueprint $table) { $table->dropColumn('display_name'); }); public function down() { Schema::table('permissions', function (Blueprint $table) { $table->dropColumn('display_name'); }); } }
3.- finally run: php artisan migrate 3.- 最后运行: php artisan migrate
And voila.瞧。 you have your new column: Hope that helps :D你有你的新专栏:希望有帮助:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.