/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(PhotoRequest $request) { $project_id = $request->input('project_id'); $featured = Input::file('featured'); $photos = Input::file('photo'); $destination = 'images'; if ($featured->isValid()) { $extension = $featured->getClientOriginalExtension(); $fileName = 'featured-' . $project_id . '.' . $extension; $photo = new Photo(['name' => $fileName]); Project::find($project_id)->photo()->save($photo); $featured->move($destination, $fileName); } $uploadcount = 1; foreach ($photos as $photo) { if ($photo->isValid()) { $extension = $photo->getClientOriginalExtension(); $fileName = 'photo' . $uploadcount . '-' . $project_id . '.' . $extension; $img = new Photo(['name' => $fileName]); Project::find($project_id)->photo()->save($img); $photo->move($destination, $fileName); $uploadcount++; } } flash()->success('Photos Successfully Uploaded!'); return redirect('/admin/photos'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(PhotoRequest $request) { if ($request->hasFile('photo')) { if ($request->file('photo')->isValid()) { $photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension(); $request->file('photo')->move(public_path('images'), $photoName); $photo = Photo::create(['url' => $photoName, 'gallery' => 1]); return back()->withNotification('Success! Image has been added to gallery.')->withType('success'); } return back()->withNotification('Error! Something went wrong.')->withType('danger'); } return back()->withNotification('Error! Something went wrong.')->withType('danger'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response */ public function store(PhotoRequest $request) { // Create new photo $photo = Photo::create(['title' => $request->get('title')]); // Set image name as suglify title in lower case $imageName = $photo->id . '.' . Str::slug($photo->title) . '.' . $request->file('image')->getClientOriginalExtension(); $imageName = Str::lower($imageName); // Move file to storage location $imagePath = storage_path() . '/uploads/img/'; $request->file('image')->move($imagePath, $imageName); // Add image filename to model $photo->update(['filename' => $imageName]); // Fire event to resize photos event(new PhotoSaved($photo)); /* * Redirect to photos route with session * of the updated entry */ return redirect()->route('dash.photos')->with(['flash_entry_updated' => true, 'flash_entry_id' => $photo->id, 'flash_entry_title' => $photo->title, 'flash_entry_route' => 'dash.photos.edit']); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update($id, Requests\PhotoRequest $request) { $photo = Photo::findOrFail($id); $photo->update($request->all()); flashMessage("The photo has been updated.", "alert-success"); return redirect('photos/list'); }