Ejemplo n.º 1
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $artwork = Artwork::find($id);
     $artwork->delete();
     return redirect('/artworks');
 }
Ejemplo n.º 2
0
 /**
  * Add image to the artwork with the id of $id
  * 
  * @param Request   $request 
  * @param int       $id
  */
 public function addArtworkImage(Request $request, $id)
 {
     $this->validate($request, ['image' => 'required|mimes:jpg,jpeg,png,bmp']);
     $artwork = Artwork::find($id);
     $media = $artwork->addArtworkImage($request->image);
     if ($media) {
         return response()->json(array('media' => $media, 'path' => $artwork->getArtworkImageUrl()), 200);
     } else {
         return response()->json(false, 500);
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  string  $slug
  * @return Response
  */
 public function update($id)
 {
     // Select the artwork you want to modify.
     $artwork = Artwork::find($id);
     // Check if you want to publish it.
     $publish = isset($_POST['publish']) ? 0 : 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);
     if ($checkSlug = Artwork::where('slug', $slug)->first()) {
         if ($artwork->id !== $checkSlug->id) {
             return Response::json([0 => 'Deze titel is al gebruikt bij een ander kunstwerk.'], HttpCode::Conflict);
         }
     }
     // Update all the fields.
     $artwork->update(['title' => $_POST['title'], 'description' => $_POST['description'], 'artist' => $_POST['artist'], 'technique' => $_POST['technique'], 'colour' => $_POST['colour'], 'material' => $_POST['material'], 'category' => $_POST['category'], 'genre' => $_POST['genre'], 'size' => $_POST['size'], 'price' => $_POST['price'], 'state' => $publish, 'slug' => $slug]);
     // Delete the old tags from an artwork and lower the total count from that tag by 1
     if (!empty(Input::get('old-tags'))) {
         $oldTags = explode(',', Input::get('old-tags'));
         foreach ($oldTags as $oldTag) {
             DB::table('tagging_tags')->where('name', $oldTag)->decrement('count', 1);
         }
         DB::table('tagging_tagged')->where('taggable_id', $artwork->id)->delete();
     }
     // Get the tags from the input if not empty and add them to the database
     if (!empty(Input::get('tags'))) {
         $tags = explode(',', Input::get('tags'));
         foreach ($tags as $tag) {
             $artwork->tag($tag);
         }
     }
     //$artwork->save();
     return redirect('artworks/' . $artwork->slug);
 }