public function photoStore($id) { $file = Input::file('image_url'); $data = Input::only(['title', 'image_url']); $rules = ['title' => 'required', 'image_url' => 'required|image|mimes:jpeg,jpg|max:1000']; $validation = Validator::make($data, $rules); if ($validation->fails()) { return Redirect::back()->withInput()->withErrors($validation->messages()); } else { $getRealPath = 'images/assets/' . date('Y') . '/'; $photo = new Photo($data); $photo->gallery_id = $id; $photo->image_url = $getRealPath . $data['image_url']->getClientOriginalName(); $photo->save(); if ($photo->save()) { $i = 0; $info = explode(".", $file->getClientOriginalName()); $newFile = $file->getClientOriginalName(); while (file_exists($getRealPath . $newFile)) { $i++; $newFile = $info[0] . "(" . $i . ")" . "." . $info[1]; } $file->move($getRealPath, $newFile); if ($newFile != $photo->image_url) { $photo->image_url = $getRealPath . $newFile; $photo->save(); } } } return Redirect::back()->with(['confirm' => 'Se inserto el registro correctamente.']); }