/** * Display the home page; * * @return Response */ public function index() { $photos = []; foreach (Photo::all() as $photo) { $ratio = $photo->height / $photo->width; $displayHeight = 900; $photos[] = ['path' => '/photos/' . $photo->name . '?fit=crop&q=80', 'width' => $displayHeight, 'height' => $ratio * $displayHeight]; } return view('pages.home', ['photos' => $photos]); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response * @throws Exception */ public function postUpload(Request $request) { DB::beginTransaction(); try { // $this->validate($request, [ // 'photos[]' => 'required|mimes:jpg,jpeg,gif,bmp,png' // ]); $images = $request->file('photos'); foreach ($images as $image) { if (!$image instanceof UploadedFile) { continue; } Photo::named($image->getClientOriginalName())->store($image)->save(); } DB::commit(); return 'Success!'; } catch (Exception $e) { DB::rollBack(); throw $e; } }