/** * 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']); }