project = $project; $this->phases = $project->phases; } public function addPhase() { Gate::authorize('edit projects', $this->project); $this->project->phases()->create([ 'name' => 'Nueva fase', 'order' => $this->phases->count() + 1, 'color' => '#' . substr(md5(random_int(0, PHP_INT_MAX)), 0, 6), ]); $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(); $this->phases = $this->project->phases()->get(); session()->flash('message', 'Fase eliminada'); } public function render() { return view('livewire.phase-list'); } }