initial commit
This commit is contained in:
commit
0c42bef077
109 changed files with 16545 additions and 0 deletions
58
app/Livewire/MovieList.php
Normal file
58
app/Livewire/MovieList.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Livewire\Forms\MovieListForm;
|
||||
use App\Models\Interfaces\MovieDbInterface;
|
||||
use App\Models\MovieList as MovieListModel;
|
||||
use Livewire\Component;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class MovieList extends Component
|
||||
{
|
||||
public int $id;
|
||||
public string $query;
|
||||
public MovieListModel $list;
|
||||
public $movies = [];
|
||||
public MovieListForm $form;
|
||||
|
||||
public function mount($id): void
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function getList()
|
||||
{
|
||||
$list = MovieListModel::with('movies')
|
||||
->find($this->id);
|
||||
|
||||
if ($list) {
|
||||
$this->list = $list;
|
||||
$this->movies = $list->movies;
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
public function addMovie(MovieDbInterface $movie_db)
|
||||
{
|
||||
$this->resetErrorBag();
|
||||
|
||||
try {
|
||||
$movie = $movie_db->search($this->query);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
$this->addError('query', 'Movie not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->list->movies()->syncWithoutDetaching($movie->id);
|
||||
$this->getList();
|
||||
$this->form->reset();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.movie-list');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue