Migrating from zizaco/entrust #1680
Unanswered
jmartindivmedianet
asked this question in
Q&A
Replies: 2 comments
-
I'm about to do the same thing. Did you work it out? |
Beta Was this translation helpful? Give feedback.
0 replies
-
For anyone ever coming across this and still needs to migrate. I added this to the migration of the package to migrate the data. // Rename entrust tables
Schema::rename('permission_domains', 'entrust_permission_domains');
Schema::rename('permission_role', 'entrust_permission_role');
Schema::rename('permissions', 'entrust_permissions');
Schema::rename('roles', 'entrust_roles');
Schema::rename('role_user', 'entrust_role_user');
/*
*
* HERE COMES THE SPATIE LARAVEL PERMISSION MIGRATION
*
*/
// Migrate Data
$roles = DB::table('entrust_roles')->get();
foreach ($roles as $role) {
DB::table($tableNames['roles'])->insert([
'id' => $role->id,
'name' => $role->name,
'guard_name' => 'web',
'display_name' => $role->display_name,
'updated_at' => $role->updated_at,
'created_at' => $role->created_at,
]);
}
$permissions = DB::table('entrust_permissions')->get();
foreach ($permissions as $permission) {
DB::table($tableNames['permissions'])->insert([
'id' => $permission->id,
'name' => $permission->name,
'guard_name' => 'web',
'display_name' => $permission->display_name,
'updated_at' => $permission->updated_at,
'created_at' => $permission->created_at,
]);
}
$rolePermission = DB::table('entrust_permission_role')->get();
foreach ($rolePermission as $pivot) {
DB::table($tableNames['role_has_permissions'])->insert([
PermissionRegistrar::$pivotPermission => $pivot->permission_id,
PermissionRegistrar::$pivotRole => $pivot->role_id,
]);
}
$roleUser = DB::table('entrust_role_user')->get();
foreach ($roleUser as $pivot) {
DB::table($tableNames['model_has_roles'])->insert([
PermissionRegistrar::$pivotRole => $pivot->role_id,
'model_type' => \App\Models\User::class,
$columnNames['model_morph_key'] => $pivot->user_id,
]);
}
app('cache')
->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
->forget(config('permission.cache.key')); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Has anyone ever worked out the basic steps for replacing zizaco/entrust with spatie/laravel-permission?
Beta Was this translation helpful? Give feedback.
All reactions