public function postDeletePhoto(DeletePhotoRequest $request) { $photo = Photo::find($request->get('id')); $this->deleteImage($photo->path); $photo->delete(); return redirect("validated/photos?id={$photo->album_id}")->with(['deleted' => 'The photo was deleted']); }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $id = $this->get('id'); $photo = Photo::find($id); $album = Auth::user()->albums()->find($photo->album_id); return $album ? true : false; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $id = $request->segment(4); $photo = Photo::find($id); if ($photo == null) { return redirect('/validated/albums'); } return $next($request); }