data(); foreach ($data as $value) { $group = PermissionGroup::updateOrCreate([ 'name' => $value['name'], 'slug' => Str::slug($value['name']) ]); foreach ($this->crudActions($group->name) as $action) { $data[] = ['name' => $action, 'group' => $group->id]; } } } public function data() { return [ ['name' => 'system-logs'], ['name' => 'audit-logs'], ]; } public function crudActions($name) { $actions = []; // list of permission actions $crud = ['create', 'read', 'update', 'delete','export', 'authorize', 'report','restore']; foreach ($crud as $value) { $actions[] = $name . '.' . $value; } return $actions; } }