Ao clicar no botão salvar aparece o seguinte erro:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'watched' in 'field list'
episodes.index:
@csrf- @foreach ($episodes as $episode)
-
Episódio {{ $episode->number }}
<input type="checkbox" name="episodes[]" value="{{ $episode->id }}" @if ($episode->watched) checked @endif /> </li> @endforeach </ul> <button class="btn btn-primary mt-2 mb-2">Salvar</button> </form>
Episodes.Controller:
public function index(Season $season)
{
return view('episodes.index', [
'episodes' => $season->episodes,
'mensagemSucesso' => session('mensagem.sucesso')
]);
}
public function update(Request $request, Season $season)
{
$watchedEpisodes = $request->episodes;
$season->episodes->each(function (Episode $episode) use ($watchedEpisodes) {
$episode->watched = in_array($episode->id, $watchedEpisodes);
});
$season->push();
return to_route('episodes.index', $season->id)
->with('mensagem.sucesso', 'Episódios marcados como assistidos');
}
** Rotas:**
Route::get('/', function () { return redirect('/series'); });
Route::resource('/series', SeriesController::class) ->except(['show']);
Route::get('/series/{series}/seasons',[ SeasonsController::class, 'index'])->name('seasons.index');
Route::get('/seasons/{season}/episodes', [EpisodesController::class, 'index'])->name('episodes.index'); Route::post('/seasons/{season}/episodes', [EpisodesController::class, 'update'])->name('episodes.update');