Example #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);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $params = $request->input();
     $artwork = new Artwork();
     $artwork->artist_firstname = $params['artist_firstname'];
     $artwork->artist_lastname = $params['artist_lastname'];
     $artwork->artist_fullname = $params['artist_firstname'] . " " . $params['artist_lastname'];
     $artwork->artwork = $params['artwork'];
     $artwork->category = $params['category'];
     $artwork->year = $params['year'];
     $artwork->medium = $params['medium'];
     $artwork->art_fair = $params['art_fair'];
     $artwork->art_fair_year = $params['art_fair_year'];
     $artwork->gallery_name = $params['gallery_name'];
     $artwork->dimensions = $params['dimensions'];
     $artwork->price = $params['price'];
     $artwork->notes = $params['notes'];
     $artwork->citation = $params['citation'];
     if ($request->file('image')) {
         $image = $request->file('image');
         $imageFileName = time() . '.' . $image->getClientOriginalExtension();
         $s3 = \Storage::disk('s3');
         $filePath = $imageFileName;
         $s3->put($filePath, file_get_contents($image), 'public');
         $storagePath = 'https://s3.amazonaws.com/artmarket-assets/' . $imageFileName;
         $artwork->image = $storagePath;
     }
     $artwork->save();
     return redirect()->action('ArtworkController@index');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // Is the user a student or moderator or admin?
     if (Auth::check() && Auth::user()->hasOnePrivelege(['Student', 'Moderator', 'Administrator'])) {
         // Get all post data
         $input = Input::all();
         // Create an artwork
         $artwork = new Artwork();
         // Set the id one higher than the amount of artworks
         $artwork->id = Artwork::max('id') + 1;
         // Set the title to the input
         $artwork->title = Input::get('title');
         // Set the description to a trimmed version of the input (removing whitespaces)
         $artwork->description = trim(Input::get('description'));
         // Set the reserved to 0
         $artwork->reserved = 0;
         $artwork->artist = Input::get('artist');
         $artwork->technique = Input::get('technique');
         $artwork->category = Input::get('category');
         $artwork->genre = Input::get('genre');
         $artwork->size = Input::get('size');
         $artwork->price = Input::get('price');
         $artwork->colour = Input::get('colour');
         $artwork->material = Input::get('material');
         // get the tags [test,mark] <-- format and split them by a , to an array
         if (!empty($input['tags'])) {
             $tags = explode(',', $input['tags']);
         }
         // Is the user a moderator or admin
         if (Auth::user()->hasOnePrivelege(['Moderator', 'Administrator'])) {
             // If the publish checkbox was checked set publish to true
             $artwork->state = Input::get('publish') == "true" ? 0 : 1;
         } else {
             // Else make it archived
             $artwork->state = 1;
         }
         // Create a slug from the title
         // replace all spaces by a -
         $slug = strtolower(implode('-', explode(' ', Input::get('title'))));
         // replace all ?, /, \\ by nothing
         $slug = str_replace('?', '', $slug);
         $slug = str_replace('/', '', $slug);
         $slug = str_replace('\\', '', $slug);
         // check if the slug already exist.
         if (Artwork::where('slug', $slug)->first()) {
             // Tell the user this title is already being used
             return Response::json([0 => 'Deze titel is al gebruikt bij een ander kunstwerk.'], HttpCode::Conflict);
         }
         // Set the slug to the slug we created
         $artwork->slug = $slug;
         $image = Image::canvas(800, 600);
         $img = Image::make(Input::get('image-data-url'))->resize(800, 600, function ($c) {
             $c->aspectRatio();
             $c->upsize();
         });
         $image->insert($img, 'center');
         // Retrieve the image
         $image = Image::make(Input::get('image-data-url'));
         // Get the image extension ex: png, jpg
         $imageExtension = substr($image->mime(), 6);
         $artwork->file = 'images/artworks/' . $artwork->id . '.jpeg';
         // set the image file to images/artworks/artwork number.extension
         $artwork->file = 'images/artworks/' . $artwork->id . '.' . $imageExtension;
         /**
          * @todo add middleware to check if logged in.
          */
         $artwork->user_id = Auth::user()->id;
         $image->save('images/artworks/' . $artwork->id . '.jpeg');
         // save it at the files place
         $image->save($artwork->file);
         // tag the artwork with all the tags
         if (!empty($tags)) {
             foreach ($tags as $tag) {
                 $artwork->tag($tag);
             }
         }
         if (Auth::check() && Auth::user()->hasOnePrivelege(['Student'])) {
             Artwork::mailArtworkRequest($artwork->slug);
         }
         // save the artwork data in the database
         $artwork->save();
         // Success
         return Response::json([0 => 'Het kunstwerk is aangemaakt klik <a href="/artworks/' . $artwork->slug . '">hier</a> om het the bekijken', 1 => 'of klik <a href="/gallery"> hier </a> om terug te keren naar de gallerij'], 200);
     } else {
         // Unauthorized error
         return Response::json([0 => 'Je bent niet geautoriseerd.'], 401);
     }
 }