45 lines
927 B
PHP
45 lines
927 B
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Livewire\Forms\MovieListForm;
|
|
use App\Models\MovieList;
|
|
use Exception;
|
|
use Livewire\Component;
|
|
|
|
class MovieLists extends Component
|
|
{
|
|
public MovieListForm $form;
|
|
public $lists = [];
|
|
|
|
public function addList(): void
|
|
{
|
|
if (!auth()->check()) {
|
|
$this->redirectRoute('login');
|
|
return;
|
|
}
|
|
|
|
$user = auth()->user();
|
|
$validated = $this->form->validate();
|
|
|
|
try {
|
|
MovieList::create(array_merge($validated, ["user_id" => $user->id]));
|
|
} catch (Exception $e) {
|
|
$this->addError("new-list", "Could not create movie list");
|
|
}
|
|
|
|
$this->getLists();
|
|
$this->form->reset();
|
|
}
|
|
|
|
public function getLists()
|
|
{
|
|
$this->lists = MovieList::all();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$this->getLists();
|
|
return view('livewire.lists');
|
|
}
|
|
}
|