2026-05-07 23:31:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire;
|
|
|
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
use Livewire\WithPagination;
|
|
|
|
|
use App\Models\Project;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
|
|
|
|
class ProjectList extends Component
|
|
|
|
|
{
|
|
|
|
|
use WithPagination;
|
|
|
|
|
|
|
|
|
|
public $search = '';
|
|
|
|
|
public $statusFilter = '';
|
|
|
|
|
|
|
|
|
|
public function deleteProject($id)
|
|
|
|
|
{
|
2026-06-17 10:36:44 +02:00
|
|
|
$user = Auth::user();
|
|
|
|
|
if (!$user->can('delete projects')) {
|
|
|
|
|
session()->flash('error', 'Sin permisos para eliminar proyectos.');
|
|
|
|
|
return;
|
2026-05-07 23:31:33 +02:00
|
|
|
}
|
2026-06-17 10:36:44 +02:00
|
|
|
// Scope to accessible projects to prevent IDOR (deleting another user's project by ID)
|
|
|
|
|
$project = Project::accessibleBy($user)->findOrFail($id);
|
|
|
|
|
$project->delete();
|
|
|
|
|
session()->flash('message', 'Proyecto eliminado');
|
2026-05-07 23:31:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
$query = Project::accessibleBy(Auth::user());
|
|
|
|
|
if ($this->search) {
|
|
|
|
|
$query->where('name', 'like', '%' . $this->search . '%');
|
|
|
|
|
}
|
|
|
|
|
if ($this->statusFilter) {
|
|
|
|
|
$query->where('status', $this->statusFilter);
|
|
|
|
|
}
|
2026-05-08 09:01:00 +02:00
|
|
|
$projects = $query->with('phases')->latest()->paginate(10);
|
2026-05-07 23:31:33 +02:00
|
|
|
return view('livewire.projects.project-list', ['projects' => $projects]);
|
|
|
|
|
}
|
|
|
|
|
}
|