We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This solution updates existing nodes and also creates new nodes if they are added. But it doesn't remove the old nodes.
$array = [ [ 'name' => 'home', 'description' => 'Painel' ], [ 'name' => 'management_group_view', 'description' => 'Gerenciamento', 'children' => [ [ 'name' => 'users_group_view', 'description' => 'Usuários', 'children' => [ array('name' => 'users_view', 'description' => 'Visualizar'), array('name' => 'users_create', 'description' => 'Criar'), array('name' => 'users_edit', 'description' => 'Editar'), array('name' => 'users_delete', 'description' => 'Deletar'), ] ], [ 'name' => 'roles_group_view', 'description' => 'Atribuições', 'children' => [ array('name' => 'roles_view', 'description' => 'Visualizar'), array('name' => 'roles_create', 'description' => 'Criar'), array('name' => 'roles_edit', 'description' => 'Editar'), array('name' => 'roles_delete', 'description' => 'Deletar'), ] ], [ 'name' => 'permissions_group_view', 'description' => 'Permissões', 'children' => [ array('name' => 'permissions_view', 'description' => 'Visualizar'), array('name' => 'permissions_create', 'description' => 'Criar'), array('name' => 'permissions_edit', 'description' => 'Editar'), array('name' => 'permissions_delete', 'description' => 'Deletar') ] ] ] ] ]; function percorrerArray($array, $parent = null) { foreach ($array as $value) { if (array_key_exists('name', $value)) { $permission = Permission::updateOrCreate( ['name' => $value['name']], [ 'description' => $value['description'], 'parent_id' => $parent ? $parent->id : null, ] ); if (array_key_exists('children', $value)) { percorrerArray($value['children'], $permission); } } } } percorrerArray($array);
The text was updated successfully, but these errors were encountered:
No branches or pull requests
This solution updates existing nodes and also creates new nodes if they are added. But it doesn't remove the old nodes.
The text was updated successfully, but these errors were encountered: