Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

1.1 KB
Raw Blame
<?php

namespace App\Livewire\Team;

use App\Actions\Team\DeleteTeam;
use App\Models\Team;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;

class DangerZone extends Component
{
    use AuthorizesRequests;

    public Team $team;

    public function mount(): void
    {
        $this->team = currentTeam();
        $this->authorize('delete', $this->team);
    }

    public function delete(): mixed
    {
        try {
            $currentTeam = currentTeam();
            $this->authorize('delete', $currentTeam);
            $newTeam = app(DeleteTeam::class)->handle($currentTeam, auth()->user());
            refreshSession($newTeam);

            return redirect()->route('team.index');
        } catch (\Throwable $e) {
            return handleError($e, $this);
        }
    }

    public function refreshResources(): void
    {
        $this->team = Team::query()->findOrFail($this->team->id);
        refreshSession($this->team);
    }

    public function render(): mixed
    {
        return view('livewire.team.danger-zone');
    }
}