Exemplo n.º 1
0
 public static function clonePost($post)
 {
     /*
      * first we make a new product useing all data
      */
     $new_post = new Post();
     $new_post->fill($post->attributes);
     $new_post->id = null;
     // Unset the primary key on the clone instead
     $new_post->save();
     /*
      * next we get all price breaks
      * and create new ones using our new
      * product model ID
      */
     $tags = $post->tags;
     foreach ($tags as $tag) {
         $data = [$new_post->id, $tag->id];
         DB::insert("INSERT INTO radiantweb_blog_post_tags (post_id,tag_id) VALUES (?,?)", $data);
     }
     /*
      * next we get all product images
      * and create new ones using our new
      * product model ID
      */
     $featured_images = $post->featured_images;
     foreach ($featured_images as $featured_image) {
         $data = [$featured_image->disk_name, $featured_image->file_name, $featured_image->file_size, $featured_image->content_type, $featured_image->title, $featured_image->description, $featured_image->field, $new_post->id, $featured_image->attachment_type, $featured_image->is_public, $featured_image->sort_order, $featured_image->created_at, $featured_image->updated_at];
         DB::insert("INSERT INTO system_files (\n                                    disk_name,\n                                    file_name,\n                                    file_size,\n                                    content_type,\n                                    title,\n                                    description,\n                                    field,\n                                    attachment_id,\n                                    attachment_type,\n                                    is_public,\n                                    sort_order,\n                                    created_at,\n                                    updated_at\n                                    ) values (?,?,?,?,?,?,?,?,?,?,?,?,?)", $data);
     }
 }