Ejemplo n.º 1
0
 /**
  * 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);
 }