Files

57 lines
1.4 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Livewire\VideoProjects;
use App\Models\VideoProject;
use Livewire\Attributes\Layout;
use Livewire\Component;
#[Layout('components.layouts.app')]
class Index extends Component
{
public bool $showForm = false;
public string $title = '';
public ?string $description = null;
public function render()
{
return view('livewire.video-projects.index', [
'projects' => VideoProject::withCount([
'steps',
'steps as completed_steps_count' => fn ($q) => $q->whereIn('status', ['completed', 'skipped']),
])
->with(['steps' => fn ($q) => $q->whereNotIn('status', ['completed', 'skipped'])->orderBy('order')->limit(1)])
->orderByDesc('created_at')
->get(),
]);
}
public function create(): void
{
$this->title = '';
$this->description = null;
$this->resetValidation();
$this->showForm = true;
}
public function save(): void
{
$validated = $this->validate([
'title' => ['required', 'string', 'max:255'],
'description' => ['nullable', 'string'],
]);
$project = VideoProject::create($validated);
$this->showForm = false;
$this->redirect(route('video-projects.show', $project), navigate: true);
}
public function delete(int $id): void
{
VideoProject::findOrFail($id)->delete();
}
}