/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $data = new Auction(); $data->users_id = Auth::user()->id; $data->schedule = $request->schedule; $data->save(); //echo json_encode($data); $data = DB::table('auctions')->orderBy('id', 'desc')->paginate(15); return view('pages.auction.index', ['data' => $data]); }
public function store(Request $request) { ///validate data if it is in databse or not $data_to_val = $request->only('product_codes'); $rule = AuctionController::getRule($request); $user = JWTAuth::parseToken()->authenticate(); ///if login $validate = Validator::make($data_to_val, $rule); if ($user->role != 1) { return response()->json(['message', 'invalid Role']); } if ($validate->fails()) { return response()->json($validate->errors()->all()); } ///open new auction $auction = new Auction(); ////add finished time this is added by 1 hr $auction->finished_at = time() + 3600; $auction->buyer()->associate($user); $auction->save(); $products = []; $product_codes = $request->get('product_codes'); foreach ($product_codes as $key => $val) { $product = Product::where(['product_code' => $val])->get()->first(); $products[$key] = $product; } $auction->products()->saveMany($products); if ($auction->products->count() >= 1) { /////Generating Defualt Bid foreach ($product_codes as $val) { $product = Product::where(['product_code' => $val])->get()->first(); $product_descriptions = $product->product_descriptions; $lowest_price_description = ProductController::findLowestPriceProductDescription($product_descriptions); $bid = new Bid(['price' => $lowest_price_description->price]); $bid->seller()->associate($lowest_price_description->seller); $bid->auction()->associate($auction); $bid->save(); $bid->products()->saveMany([$product]); } //// if ($auction->bids->count() >= 1) { $auction->status = 0; //opening $auction->save(); return response()->json(['message', 'success']); } } return response()->json(['message', 'error occurred']); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $this->validate($request, ['title' => 'required|unique:auctions|max:255', 'artist' => 'required|max:255', 'year' => 'required|integer|digits_between:3,4|max:2016', 'width' => 'required|numeric', 'height' => 'required|numeric', 'depth' => 'numeric', 'description' => 'required|max:255', 'condition' => 'required|max:255', 'origin' => 'required|max:255', 'picture' => 'required', 'minprice' => 'required|numeric|', 'buyout' => 'required|numeric|greater_than_field:minprice', 'date' => 'required|date|after:today', 'terms' => 'required|accepted']); $artist = Artist::where('name', $request->artist)->first(); if (!$artist) { $artist = new Artist(['name' => $request->artist]); } $artist->save(); $auction = new Auction(['title' => $request->title, 'description' => $request->description, 'start' => Carbon::now(), 'end' => $request->date, 'buy_now' => $request->buyout, 'price' => $request->minprice, 'status' => 'Active', 'style_id' => Style::Where('name', $request->style)->first()->id]); $artwork = new Artwork(['name' => $request->title, 'width' => $request->width, 'height' => $request->height, 'depth' => $request->depth, 'condition' => $request->condition, 'origin' => $request->origin, 'year' => $request->year]); $auction->save(); $artwork->auction()->associate($auction); $artwork->save(); // Picture save $imageName = $artwork->id . '.' . $request->file('picture')->getClientOriginalExtension(); $artwork->image = $imageName; $request->file('picture')->move(base_path() . '/public/img/', $imageName); $artist->artworks()->save($artwork); $owner = $request->user(); $owner->auctionsowner()->save($auction); return redirect('/auctions/' . $owner->id); }
public function store(Request $request) { $validator = Validator::make($request->all(), ['title' => 'required|max:255|regex:/(^[A-Za-z0-9 ]+$)+/', 'width' => 'required|max:20', 'year' => 'required|integer|max:2016', 'height' => 'required|max:20', 'depth' => 'required|max:20', 'descriptionEnglish' => 'required|max:255', 'descriptionDutch' => 'required|max:255', 'conditionEnglish' => 'required|max:255', 'conditionDutch' => 'required|max:255', 'originEnglish' => 'required|max:255', 'originDutch' => 'required|max:255', 'conditionDutch' => 'required|max:255', 'minPrice' => 'required|min:1|max:9999999999|integer', 'maxPrice' => 'required|min:1|max:9999999999|integer', 'buyoutPrice' => 'required|min:1|max:9999999999|integer', 'enddate' => 'required|date', 'artist' => 'required|not_in:0', 'era' => 'required|not_in:0', 'color' => 'required|not_in:0', 'style' => 'required|not_in:0', 'category' => 'required|not_in:0', 'imageArtwork' => 'required', 'imageSignature' => 'required']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } $input = $request->all(); if ($input['minPrice'] > $input['maxPrice']) { return redirect()->back()->with('priceError', 'The minimum price must be lower as the maximum price!')->withInput(); } if ($input['maxPrice'] > $input['buyoutPrice']) { return redirect()->back()->with('priceError', 'The buyout price must be higher as the maximum price!')->withInput(); } $auction = new Auction(); $auction->FK_user_id = Auth::user()->id; $auction->title = $input['title']; $auction->width = $input['width']; $auction->year = $input['year']; $auction->height = $input['height']; $auction->depth = $input['depth']; $auction->descriptionEnglish = $input['descriptionEnglish']; $auction->descriptionDutch = $input['descriptionDutch']; $auction->conditionEnglish = $input['conditionEnglish']; $auction->conditionDutch = $input['conditionDutch']; $auction->originEnglish = $input['originEnglish']; $auction->originDutch = $input['originDutch']; $auction->minPrice = $input['minPrice']; $auction->currentPrice = $input['minPrice']; //de huidige prijs op de minimum prijs zetten $auction->maxPrice = $input['maxPrice']; $auction->buyoutPrice = $input['buyoutPrice']; $auction->enddate = $input['enddate']; $artist = explode(',', $input['artist']); $auction->FK_artist_id = $artist[0]; $era = explode(',', $input['era']); $auction->FK_era_id = $era[0]; $color = explode(',', $input['color']); $auction->FK_color_id = $color[0]; $style = explode(',', $input['style']); $auction->FK_style_id = $style[0]; $category = explode(',', $input['category']); $auction->FK_category_id = $category[0]; $auction->FK_status_id = '1'; //pending $directory = public_path() . '/images/uploads/' . Auth::user()->email . '/'; File::makeDirectory($directory, 0777, true, true); $file = array('image' => $input['imageArtwork']); if (isset($file['image'])) { $img_rule = array('imageArtwork' => 'image'); $img_validator = Validator::make($file, $img_rule); if ($img_validator->fails()) { return Redirect::route('createAuction')->withErrors($img_validator); } else { $extension = null; $extension = $input['imageArtwork']->getClientOriginalExtension(); $filename = "Artwork_" . $input['title'] . "." . $extension; Input::file('imageArtwork')->move($directory, $filename); $auction->imageArtwork = '/images/uploads/' . Auth::user()->email . '/' . $filename; } } $file = array('image' => $input['imageSignature']); if (isset($file['image'])) { $img_rule = array('imageSignature' => 'image'); $img_validator = Validator::make($file, $img_rule); if ($img_validator->fails()) { return Redirect::route('createAuction')->withErrors($img_validator); } else { $extension = null; $extension = $input['imageSignature']->getClientOriginalExtension(); $filename = "Signature_" . $input['title'] . "." . $extension; Input::file('imageSignature')->move($directory, $filename); $auction->imageSignature = '/images/uploads/' . Auth::user()->email . '/' . $filename; } } if (Input::file('file_url') != null) { $file = array('image' => $input['imageOptional']); if (isset($file['image'])) { $img_rule = array('imageOptional' => 'image'); $img_validator = Validator::make($file, $img_rule); if ($img_validator->fails()) { return Redirect::route('createAuction')->withErrors($img_validator); } else { $extension = null; $extension = $input['imageOptional']->getClientOriginalExtension(); $filename = "Optional_" . $input['title'] . "." . $extension; Input::file('imageOptional')->move($directory, $filename); $auction->imageOptional = '/images/uploads/' . Auth::user()->email . '/' . $filename; } } } $auction->save(); return Redirect::route('createAuction')->with('success', 'Auction succesfully added!'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $locale = App::getLocale(); $this->validate($request, ['style_id' => 'required', 'title' => 'required|max:255', 'year' => 'required', 'width' => 'required|numeric', 'height' => 'required|numeric', 'artist' => 'required', 'description' => 'required', 'condition' => 'required', 'origin' => 'required', 'image_artwork' => 'required', 'image_signature' => 'required', 'minimum_price' => 'required', 'maximum_price' => 'required', 'buyout_price' => 'required', 'end_date' => 'required', 'terms_conditions' => 'accepted']); $data = $request->all(); $auction = new Auction(); $auction->user_id = Auth::id(); $auction->category_id = 1; $auction->media_id = 1; $auction->style_id = $data['style_id']; $auction->color_id = 1; $auction->artist = $data['artist']; $auction->year = $data['year']; $auction->width = $data['width']; $auction->height = $data['height']; $auction->depth = $data['depth']; if ($request->hasFile('image_artwork')) { $file = $request->file('image_artwork'); $fileName = time() . '.' . $file->getClientOriginalExtension(); $fileNameThumb = 'thumb-' . time() . '.' . $file->getClientOriginalExtension(); $dir = 'img/uploads/' . strtolower(str_slug(Auth::user()->name, '-')); $path = public_path($dir . '/' . $fileName); $pathThumb = public_path($dir . '/' . $fileNameThumb); if (!\File::isDirectory($dir)) { File::makeDirectory($dir, $mode = 0777, true, true); } Image::make($file->getRealPath())->resize(768, null, function ($constraint) { $constraint->aspectRatio(); })->save($pathThumb); Image::make($file->getRealPath())->resize(2000, null, function ($constraint) { $constraint->aspectRatio(); })->save($path); $auction->image_artwork = 'uploads/' . strtolower(str_slug(Auth::user()->name, '-') . '/') . '/' . $fileName; } if ($request->hasFile('image_signature')) { $file = $request->file('image_signature'); $fileName = time() . '.' . $file->getClientOriginalExtension(); $fileNameThumb = 'thumb-' . time() . '.' . $file->getClientOriginalExtension(); $dir = 'img/uploads/' . strtolower(str_slug(Auth::user()->name, '-')); $path = public_path($dir . '/' . $fileName); $pathThumb = public_path($dir . '/' . $fileNameThumb); if (!\File::isDirectory($dir)) { File::makeDirectory($dir, $mode = 0777, true, true); } Image::make($file->getRealPath())->resize(768, null, function ($constraint) { $constraint->aspectRatio(); })->save($pathThumb); Image::make($file->getRealPath())->resize(2000, null, function ($constraint) { $constraint->aspectRatio(); })->save($path); $auction->image_signature = 'uploads/' . strtolower(str_slug(Auth::user()->name, '-')) . '/' . $fileName; } if ($request->hasFile('image_optional')) { $file = $request->file('image_optional'); $fileName = time() . '.' . $file->getClientOriginalExtension(); $fileNameThumb = 'thumb-' . time() . '.' . $file->getClientOriginalExtension(); $dir = 'img/uploads/' . strtolower(str_slug(Auth::user()->name, '-')); $path = public_path($dir . '/' . $fileName); $pathThumb = public_path($dir . '/' . $fileNameThumb); if (!\File::isDirectory($dir)) { File::makeDirectory($dir, $mode = 0777, true, true); } Image::make($file->getRealPath())->resize(768, null, function ($constraint) { $constraint->aspectRatio(); })->save($pathThumb); Image::make($file->getRealPath())->resize(2000, null, function ($constraint) { $constraint->aspectRatio(); })->save($path); $auction->image_optional = 'uploads/' . strtolower(str_slug(Auth::user()->name, '-')) . '/' . $fileName; } //$auction->image_artwork = 'http://www.fillmurray.com/g/1920/800'; //$auction->image_signature = 'http://www.fillmurray.com/g/1920/700'; //$auction->image_optional = 'http://www.fillmurray.com/g/1920/600'; $auction->minimum_price = $data['minimum_price']; $auction->maximum_price = $data['maximum_price']; $auction->buyout_price = $data['buyout_price']; $auction->current_price = '0'; $auction->updated_at = Carbon::now(); $auction->end_date = $data['end_date']; $auction->save(); $auction->translateOrNew($locale)->title = $data['title']; $auction->translateOrNew($locale)->slug = str_slug($data['title']); $auction->translateOrNew($locale)->description = $data['description']; $auction->translateOrNew($locale)->condition = $data['condition']; $auction->translateOrNew($locale)->origin = $data['origin']; $auction->save(); return Redirect::back(); }
public function auction1() { //Buyer 1 Product $data = ['name' => 'buyer', 'email' => '*****@*****.**', 'password' => Hash::make('buyer'), 'role' => '1']; $user = User::firstOrCreate($data); $user->save(); $product = Product::firstOrNew(['product_code' => '12345']); $product1 = Product::firstOrNew(['product_code' => '12346']); $product2 = Product::firstOrNew(['product_code' => '12347']); $product3 = Product::firstOrNew(['product_code' => '12348']); $product4 = Product::firstOrNew(['product_code' => '12349']); $data = ['finished_at' => time() + 3600]; $auction = new Auction($data); $auction->buyer()->associate($user); $auction->save(); $products = [$product, $product1, $product2, $product3, $product4]; $auction->products()->saveMany($products); }