/**
  * Sweet baby jesus hashtag2
  *
  * @param                     $userId
  * @param                     $blueprintId
  * @param PathBuilder         $pathBuilder
  * @param Blueprint           $blueprintModel
  * @param BlueprintCollection $blueprintCollection
  * @param Filesystem          $file
  * @param Repository          $repository
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postDeleteBlueprint($userId, $blueprintId, PathBuilder $pathBuilder, Blueprint $blueprintModel, BlueprintCollection $blueprintCollection, Filesystem $file, Repository $repository)
 {
     $blueprint = $blueprintModel->where(['id' => $blueprintId])->first()->toArray();
     $blueprintScreenshootRequired = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.images')) . $blueprint['screenshot'];
     // append the archive name name to the default storage path
     $blueprintArchive = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.archives')) . $blueprint['archive_name'];
     // append the screenshoot name to the default storage path
     if ($file->exists($blueprintScreenshootRequired)) {
         $file->delete($blueprintScreenshootRequired);
     }
     if ($file->exists($blueprintArchive)) {
         $file->delete($blueprintArchive);
     }
     if (null !== $blueprint['screenshot_optional_0']) {
         $blueprintScreenshootOptiona_0 = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.images')) . $blueprint['screenshot_optional_0'];
         // append the screenshoot name to the default storage path
         if ($file->exists($blueprintScreenshootOptiona_0)) {
             $file->delete($blueprintScreenshootOptiona_0);
         }
     }
     if (null !== $blueprint['screenshot_optional_1']) {
         $blueprintScreenshootOptiona_1 = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.images')) . $blueprint['screenshot_optional_1'];
         // append the screenshoot name to the default storage path
         if ($file->exists($blueprintScreenshootOptiona_1)) {
             $file->delete($blueprintScreenshootOptiona_1);
         }
     }
     // Delete any association of this blueprint with any collection
     $blueprintCollection->where(['blueprint_id' => $blueprintId])->delete();
     if ($blueprintModel->destroy($blueprintId)) {
         return redirect()->route('buildcraft::user::uploads', ['user_id' => $userId])->with('blueprintDeleteSuccess', true);
     }
     return redirect()->route('buildcraft::user::uploads', ['user_id' => $userId])->with('blueprintDeleteSuccess', false);
 }
 public function add(Zipper $zipper, PathBuilder $pathBuilder, Request $request, BlueprintCollection $blueprintCollection, Filesystem $file, Repository $repository, Collection $collection)
 {
     $input = $request->get('collection');
     // Check if the blueprint already belongs to this collection
     $search = $blueprintCollection->where(['collection_id' => $input['id'], 'blueprint_id' => $input['blueprint_id']])->get()->toArray();
     if (!empty($search)) {
         return redirect()->back()->with('blueprintAlreadyInCollection', true);
     }
     // Insert the blueprint in the collection
     $insert = $blueprintCollection->insert(['collection_id' => $input['id'], 'blueprint_id' => $input['blueprint_id']]);
     if ($insert) {
         // Create an archive to server to the user rather than creating it when it's downloaded
         // Get all the collection current archives first
         $collection = $collection->select('id', 'archive_name', 'name')->where(['id' => $input['id']])->with(['blueprints' => function ($query) {
             $query->select('archive_name');
         }])->first();
         $buildcraftArchiveStoragePath = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.archives'));
         // Delete the previous archive(if any)
         if (null !== $collection->archive_name) {
             $file->delete($buildcraftArchiveStoragePath . $collection->archive_name);
         }
         // Create a random name for the collection archive
         $collectionArchiveName = str_replace(' ', '', $collection->name) . '_' . getRandomId() . '_collection' . '.zip';
         // Start creating the archive
         $zipper->make($buildcraftArchiveStoragePath . $collectionArchiveName);
         foreach ($collection->blueprints as $key => $value) {
             // Add each archive to the the newly created archive
             $zipper->add($buildcraftArchiveStoragePath . $value->archive_name);
         }
         //Clean up
         $zipper->close();
         // Update the archive name in the collections table
         $collection->archive_name = $collectionArchiveName;
         $collection->save();
         // Welp, that's that
         return redirect()->back()->with('blueprintAddedToCollection', true);
     }
     // Or not
     return redirect()->back()->with('blueprintNotAddedToCollection', true);
 }