public function createMultiple(Request $request, $movie_id) { $pureRequest = $request; $section_id = isset($_POST['section_id']) ? $_POST['section_id'] : false; $site_location = $_POST['site_location'] != '' ? $_POST['site_location'] : NULL; $files = $pureRequest->file('image') ? $pureRequest->file('image') : NULL; foreach ($files as $file) { if ($file->isValid()) { $movie = Movie::findOrFail($movie_id); $movieTitle = Helper::movieTitle($movie->title); $imgPath = public_path() . "/movies/{$movieTitle}/img/"; $filename = $file->getClientOriginalName(); if (file_exists($imgPath . $filename)) { $filenameExploded = explode('.', $filename); $filename = $filenameExploded[0] . "-1" . $filenameExploded[1]; } $file->move($imgPath, $filename); $image = new Image(); $image->title = $pureRequest->get('title'); $image->path = "/movies/{$movieTitle}/img/{$filename}"; $image->site_location = $site_location; $image->movie_id = $movie_id; $image->section_id = $section_id; $image->save(); } } return redirect("admin/movies/{$movie_id}/edit/sections/{$section_id}"); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(MovieRequest $request) { Movie::create($request->all()); return redirect('admin'); }