public function actionUpdate($id, Requests\UpdateMovieRequest $request) { // Set authenticated user into user variable. $user = Auth::user(); // Find by id the id sent via the form and set into movie variable. $movie = Movie::where('user_id', '=', $user->id)->findOrFail($id); // Save request to the database. $movie->update($request->all()); // Syncing genres to movies via pivot table. $genres = $request->input('genres'); if (!is_array($genres)) { $genres = []; } $genreSync = $this->checkGenres($genres); $movie->genres()->sync($genreSync); // Syncing ratings to movies via pivot table. $ratings = $request->input('ratings'); if (!is_array($ratings)) { $ratings = []; } $ratingSync = $this->checkRatings($ratings); $movie->ratings()->sync($ratingSync); // Syncing directors to movies via pivot table. $directors = $request->input('directors'); if (!is_array($directors)) { $directors = []; } $directorSync = $this->checkDirectors($directors); $movie->directors()->sync($directorSync); // Syncing writers to movies via pivot table. $writers = $request->input('writers'); if (!is_array($writers)) { $writers = []; } $writerSync = $this->checkWriters($writers); $movie->writers()->sync($writerSync); // Syncing cast to movies via pivot table. $casts = $request->input('casts'); if (!is_array($casts)) { $casts = []; } $castSync = $this->checkCasts($casts); $movie->casts()->sync($castSync); // Syncing labels to movies via pivot table $labels = $request->input('labels'); if (!is_array($labels)) { $labels = []; } $labelSync = $this->checkLabels($labels); $movie->labels()->sync($labelSync); // Send flash message. \Session::flash('flash_message', 'You have successfully updated this movie.'); // Redirecting to movies page. return redirect('/movies/' . $movie->id); }