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); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(UpdateMovieRequest $request, $id) { $name = $request->input('name'); $category_id = $request->input('category_id'); $director = $request->input('director'); $genre = $request->input('genre'); $synopsis = $request->input('synopsis'); $price = $request->input('price'); $main_image = $request->file('main_image'); $image1 = $request->file('_image1'); $image2 = $request->file('_image2'); $image3 = $request->file('_image3'); $quantity = $request->file('quantity'); $current_mainimage_filename = Movie::find($id)->main_image; $current_image1_filename = Movie::find($id)->_image1; $current_image2_filename = Movie::find($id)->_image2; $current_image3_filename = Movie::find($id)->_image3; // Check if image(s) uploaded successfully if ($main_image) { $main_image_filename = $main_image->getClientOriginalName(); $main_image->move(public_path('images/uploaded'), $main_image_filename); } else { $main_image_filename = $current_mainimage_filename; } if ($image1) { $image1_filename = $image1->getClientOriginalName(); $image1->move(public_path('images/uploaded'), $image1_filename); } else { $image1_filename = $current_image1_filename; } if ($image2) { $image2_filename = $image2->getClientOriginalName(); $image2->move(public_path('images/uploaded'), $image2_filename); } else { $image2_filename = $current_image2_filename; } if ($image3) { $image3_filename = $image3->getClientOriginalName(); $image3->move(public_path('images/uploaded'), $image3_filename); } else { $image3_filename = $current_image3_filename; } // Update command $command = new UpdateMovieCommand($id, $name, $category_id, $director, $genre, $synopsis, $price, $main_image_filename, $image1_filename, $image2_filename, $image3_filename, $quantity); $this->dispatch($command); return \Redirect::route('movies.index')->with('flash_message', 'Update Successful'); }