Role::query()->create([ 'name' => $data->name, 'guard_name' => 'web', ])); return RoleData::from($role); } /** * @throws InvalidArgumentException when id is invalid. * @throws Throwable when an error occurs during the deletion. */ public function delete(int $id): void { if ($id <= 0) { throw new InvalidArgumentException('Invalid id'); } DB::transaction(function () use ($id): void { Role::query()->findOrFail($id)->delete(); }); } /** * Returns a Paginated Collection of roles with their connected apps DTO * * @return PaginatedDataCollection */ #[NoDiscard] public function getAll(): PaginatedDataCollection { $roles = Role::query() ->with('apps') ->orderBy('id') ->paginate(); return RoleData::collect($roles, PaginatedDataCollection::class); } }