Files
construprogress/app/Livewire/PhaseList.php
T

55 lines
1.4 KiB
PHP
Raw Normal View History

2026-05-07 23:31:33 +02:00
<?php
namespace App\Livewire;
use Livewire\Component;
use App\Models\Project;
use App\Models\Phase;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
2026-05-07 23:31:33 +02:00
class PhaseList extends Component
{
public Project $project;
public $phases;
public function mount(Project $project)
{
Gate::authorize('edit projects', $project);
2026-05-07 23:31:33 +02:00
$this->project = $project;
$this->phases = $project->phases;
2026-05-07 23:31:33 +02:00
}
public function addPhase()
{
Gate::authorize('edit projects', $this->project);
2026-05-07 23:31:33 +02:00
$this->project->phases()->create([
'name' => 'Nueva fase',
2026-05-07 23:31:33 +02:00
'order' => $this->phases->count() + 1,
'color' => '#' . substr(md5(random_int(0, PHP_INT_MAX)), 0, 6),
2026-05-07 23:31:33 +02:00
]);
$this->phases = $this->project->phases()->get();
session()->flash('message', 'Fase agregada');
}
public function deletePhase($phaseId)
{
Gate::authorize('edit projects', $this->project);
// Scope to this project to prevent IDOR deletion of another project's phase
Phase::where('id', $phaseId)
->where('project_id', $this->project->id)
->firstOrFail()
->delete();
2026-05-07 23:31:33 +02:00
$this->phases = $this->project->phases()->get();
session()->flash('message', 'Fase eliminada');
2026-05-07 23:31:33 +02:00
}
public function render()
{
return view('livewire.phase-list');
}
}