/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(AuctionCreateRequest $request) { $input = $request->all(); $imgPath = 'img/uploads/'; $timestamp = time(); $fileProperties = ['img_artwork', 'img_signature', 'img_optional']; foreach ($fileProperties as $fileProperty) { if ($request->hasFile($fileProperty)) { $file = $request->file($fileProperty); $extension = $file->getClientOriginalExtension(); $randomstring = self::generateRandomString(20); $filename = $timestamp . '-' . $randomstring . '.' . $extension; $file->move($imgPath, $filename); $input[$fileProperty] = '/' . $imgPath . $filename; } } $input['enddate'] = Carbon::createFromFormat('Y-m-d', $input['enddate']); $auction = Auction::create($input); $owner = Auth::user(); $auction->owner()->associate($owner); $style = AuctionStyle::findOrFail($request->get('auction_style_id')); $auction->auctionstyles()->associate($style); $auction->save(); return redirect()->route('myauctions.index'); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('auctions')->delete(); $owner = User::first(); $style_first = AuctionStyle::first(); $style_random = AuctionStyle::orderByRaw("RAND()")->first(); Auction::create(['owner_id' => $owner->id, 'auction_style_id' => $style_first->id, 'title' => 'La trahison des images - René Magritte', 'year' => 1928, 'width' => '63.5', 'height' => '93.98', 'depth' => null, 'description' => 'The Treachery of Images (sometimes translated as The Treason of Images) is a painting by the Belgian surrealist painter René Magritte.', 'condition' => 'Great', 'origin' => 'Belgium', 'img_artwork' => '/img/uploads/magritte_1.jpg', 'img_signature' => '/img/uploads/magritte_2.png', 'img_optional' => null, 'min_price' => '20000', 'max_price' => '1000000', 'buyout_price' => '1000000', 'enddate' => Carbon::parse('last wednesday')->format('Y-m-d')]); Auction::create(['owner_id' => $owner->id, 'auction_style_id' => $style_random->id, 'title' => 'Skrik - Edvard Munch', 'year' => 1893, 'width' => '91', 'height' => '73.5', 'depth' => null, 'description' => 'The Scream (Norwegian: Skrik) is the popular name given to each of four versions of a composition, created as both paintings and pastels, by the Expressionist artist Edvard Munch between 1893 and 1910. The Greman title Munch gave these works is Der Schrei der Natur (The Scream of Nature). The works show a figure with an agonized expression against a landscape with a tumultuous orange sky. Arthur Lubow has described The Scream as "an icon of modern art, a Mona Lisa for our time."', 'condition' => 'Okay', 'origin' => 'Oslo', 'img_artwork' => '/img/uploads/scream_1.jpg', 'img_signature' => '/img/uploads/scream_2.jpg', 'img_optional' => '/img/uploads/scream_3.jpg', 'min_price' => '7500', 'max_price' => '1355000', 'buyout_price' => '1000000', 'enddate' => Carbon::parse('next saturday')->format('Y-m-d')]); for ($i = 0; $i < 50; $i++) { Auction::create(['owner_id' => $owner->id, 'auction_style_id' => $style_random->id, 'title' => 'FILLER ' . $i, 'year' => rand(1000, 2000), 'width' => rand(10, 100), 'height' => rand(10, 100), 'depth' => null, 'description' => "FILLER DESCRIPTION Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.", 'condition' => 'Fine', 'origin' => 'World', 'img_artwork' => '/img/uploads/filler_' . rand(1, 8) . '.jpg', 'img_signature' => '/img/uploads/filler_' . rand(1, 8) . '.jpg', 'img_optional' => null, 'min_price' => rand(100, 1000), 'max_price' => rand(2000, 20000), 'buyout_price' => 20000, 'enddate' => Carbon::parse('next thursday')->format('Y-m-d')]); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $this->validate($request, ['style' => 'required', 'title' => 'required|max:255', 'author' => 'required', 'year' => 'required', 'width' => 'required|numeric', 'height' => 'required|numeric', 'description' => 'required', 'condition' => 'required', 'origin' => 'required', 'img_artwork' => 'required', 'img_signature' => 'required', 'minprice' => 'required', 'maxprice' => 'required', 'buyoutprice' => 'required', 'enddate' => 'required', 'termsandconditions' => 'accepted']); $data = $request->all(); $artwork_image = $this->auction->moveFile($request, "img_artwork", Auth::user()->id, $data['title']); $signature_image = $this->auction->moveFile($request, "img_signature", Auth::user()->id, $data['title']); if ($request->hasFile('photo')) { $this->auction->moveFile($request, "img_optional", Auth::user()->id, $data['title']); $optional_image = $request->file('img_optional'); } else { $optional_image = ''; } $correct_date = $this->auction->formatDate($data['enddate']); $remaining_time = $this->auction->convertToRemainingTime($correct_date); Auction::create(['user_id' => Auth::user()->id, 'style' => $data['style'], 'title' => $data['title'], 'author' => $data['author'], 'year' => $data['year'], 'width' => $data['width'], 'height' => $data['height'], 'depth' => $data['depth'], 'description' => $data['description'], 'condition' => $data['condition'], 'origin' => $data['origin'], 'img_artwork' => $artwork_image, 'img_signature' => $signature_image, 'img_optional' => $optional_image, 'minprice' => $data['minprice'], 'maxprice' => $data['maxprice'], 'estprice' => ((int) $data['minprice'] + (int) $data['maxprice']) / 2, 'buyoutprice' => $data['buyoutprice'], 'enddate' => $correct_date, 'pending' => true, 'refused' => false, 'active' => false, 'expired' => false, 'sold' => false]); return redirect('/myauctions'); }
public function store(Request $request) { $this->validate($request, ['title' => 'required|unique:auctions', 'expires' => 'required', 'min_price' => 'required', 'max_price' => 'required', 'buying_price' => 'required', 'artist' => 'required', 'year' => 'required|max:4', 'width' => 'required|numeric', 'height' => 'required|numeric', 'depth' => 'numeric', 'description' => 'required', 'condition' => 'required', 'style_id' => 'required', 'artwork' => 'required|mimes:jpeg,bmp,png,gif,jpg,JPG,JPEG|max:10240', 'signature' => 'required|mimes:jpeg,bmp,png,gif,jpg,JPG,JPEG|max:10240', 'opt_img' => 'mimes:jpeg,bmp,png,gif,jpg,JPG,JPEG|max:10240']); $input = $request->all(); $input['expires'] = date_create_from_format('d/m/Y', $input['expires']); $input['state'] = 'pending'; $input['seller_id'] = Auth::user()->id; $input['slug'] = Auction::sluggify($input['title']); $input['dimensions'] = $input['width'] . ' x ' . $input['height']; if (isset($input['depth'])) { $input['dimensions'] .= ' x ' . $input['depth']; unset($input['depth']); } $input['dimensions'] .= ' cm'; unset($input['width']); unset($input['height']); // Set image filename $artName = $request->file('artwork')->GetClientOriginalName(); $sigName = $request->file('signature')->GetClientOriginalName(); // Set destination path for images $userPath = 'img/' . Auth::user()->id . '/'; $destPath = $userPath . $input['slug'] . '/'; $thumbPath = $destPath . 'thumbs/'; // Send image path to database for performance $input['artwork'] = $destPath . $artName; $input['signature'] = $destPath . $sigName; $input['thumb'] = $thumbPath . $artName; $input['sig_thumb'] = $thumbPath . $sigName; // Handle optional image if (isset($input['opt_img'])) { $optName = $request->file('opt_img')->GetClientOriginalName(); $input['opt_img'] = $destPath . $optName; $input['opt_thumb'] = $thumbPath . $optName; } Auction::create($input); // Save images to images/{user_id}/{slug} folder if (!file_exists($userPath)) { mkdir($userPath); } if (!file_exists($destPath)) { mkdir($destPath); } if (!file_exists($thumbPath)) { mkdir($thumbPath); } $img = Image::make($request->file('artwork')->getRealPath())->resize(1024, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->save(public_path($input['artwork'])); $img = Image::make($request->file('signature')->getRealPath())->resize(1024, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->save(public_path($input['signature'])); // thumbify Auction::thumbify($request->file('artwork')->getRealPath(), $thumbPath . $artName); Auction::thumbify($request->file('signature')->getRealPath(), $thumbPath . $sigName); if ($request->file('opt_img') !== NULL) { $opt_img = Image::make($request->file('opt_img')->getRealPath())->resize(1024, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->save(public_path($input['opt_img'])); Auction::thumbify($request->file('opt_img')->getRealPath(), $thumbPath . $optName); } Session::flash('flash_message', trans('auctions.create.success')); return redirect(Lang::locale() . '/myauctions'); }
public function store(addAuctionRequest $request) { $auth_user = User::where('login_id', '=', Auth::id())->first(); $input = $request->all(); $input['published'] = Carbon::now(); $input['end_date'] = Carbon::createFromFormat('d/m/y', $request['end_date']); $input['user_id'] = $auth_user->id; $input['active'] = '1'; // initialize $count = 0; $type = ''; /* --------------- */ $files = []; if ($request->file('image_art')) { $files[] = $request->file('image_art'); } if ($request->file('image_sign')) { $files[] = $request->file('image_sign'); } if ($request->file('image_opt')) { $files[] = $request->file('image_opt'); } $rules = array(); $validator = Validator::make($files, $rules); if ($validator->fails()) { return Redirect::route('addauction')->withInput()->withErrors($validator); } else { $inserted = Auction::create($input); foreach ($files as $file) { $count++; if (!empty($file)) { if ($file->isValid()) { $destinationPath = 'images/arts'; $extension = $file->getClientOriginalExtension(); // getting image extension switch ($count) { case 1: $type = 'art'; break; case 2: $type = 'sign'; break; case 3: $type = 'opt'; break; } $fileName = $type . '_' . $inserted->id . '.' . $extension; $file->move($destinationPath, $fileName); $image['auction_id'] = $inserted->id; $image['filename'] = $fileName; $image['extension'] = $extension; $image['type'] = $type; Image::create($image); } else { return Redirect::route('addauction')->withInput()->withErrors(['msg', 'The Message']); } } } } return Redirect::route('myauctions'); }