Esempio n. 1
0
 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     if ($this->step instanceof GuideStep) {
         $position = (int) $this->request->input('position', 1);
         return $this->step->insertAt($position);
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Catches and runs operations when a guide step is deleted.
  *
  * @param GuideStep $step
  */
 public function deleting(GuideStep $step)
 {
     if (!$step->deleted_at) {
         $files = $step->images()->get();
         foreach ($files as $file) {
             $file->delete();
         }
     }
 }
Esempio n. 3
0
 /**
  * Execute the job.
  *
  * @return GuideStep|bool
  */
 public function handle()
 {
     $this->step->title = $this->request->input('title', $this->step->title);
     $this->step->description = $this->request->input('description', $this->step->description);
     if ($this->step->save()) {
         // If saving the step is successful, we'll process the file upload if there is one.
         $file = $this->request->file('image');
         if ($file instanceof UploadedFile) {
             $this->step->deleteFiles();
             $this->step->uploadFile($file, $path = null, $resize = true);
         }
         return $this->step;
     }
     return false;
 }
Esempio n. 4
0
 /**
  * Persist the changes.
  *
  * @param Guide     $guide
  * @param GuideStep $step
  *
  * @return GuideStep|bool
  */
 public function persist(Guide $guide, GuideStep $step)
 {
     $step->guide_id = $guide->id;
     $step->title = $this->input('title');
     $step->description = $this->input('description');
     if ($step->save()) {
         // Retrieve the image for the step.
         $file = $this->file('image');
         if ($file instanceof UploadedFile) {
             $step->deleteFiles();
             $step->uploadFile($file, $path = null, $resize = true);
         }
         // No image was uploaded, we'll return the step.
         return $step;
     }
     return false;
 }
Esempio n. 5
0
 /**
  * Returns a new form of the guide step.
  *
  * @param Guide     $guide
  * @param GuideStep $step
  *
  * @return \Orchestra\Contracts\Html\Builder
  */
 public function form(Guide $guide, GuideStep $step)
 {
     return $this->form->of('resources.guides.steps', function (FormGrid $form) use($guide, $step) {
         if ($step->exists) {
             $method = 'patch';
             $url = route('resources.guides.steps.update', [$guide->slug, $step->getPosition()]);
             $form->submit = 'Save';
         } else {
             $method = 'post';
             $url = route('resources.guides.steps.store', [$guide->slug]);
             $form->submit = 'Create';
         }
         $files = true;
         $form->attributes(compact('method', 'url', 'files'));
         $form->with($step);
         $form->layout('pages.resources.guides.steps._form');
         $form->fieldset(function (Fieldset $fieldset) use($guide, $step) {
             $hasImage = count($step->images) > 0;
             foreach ($step->images as $image) {
                 $fieldset->control('input:text', 'remove', function ($control) use($guide, $step, $image) {
                     $control->label = 'Image(s)';
                     // Generate a field for removing images from the current step.
                     $control->field = function () use($guide, $step, $image) {
                         // Generate the url of the image.
                         $url = route('resources.guides.steps.images.download', [$guide->slug, $step->id, $image->uuid]);
                         // Generate the HTML image tag
                         $photo = HTML::image($url, null, ['class' => 'img-responsive']);
                         // Generate the button for deleting the current image.
                         $button = HTML::link(route('resources.guides.steps.images.destroy', [$guide->slug, $step->id, $image->uuid]), 'Delete', ['class' => 'btn btn-danger', 'data-post' => 'DELETE', 'data-title' => 'Delete Image?', 'data-message' => 'Are you sure you want to delete this image?']);
                         // Return the result as raw HTML.
                         return HTML::raw("<div class='col-md-6 text-center'>{$photo} <br> {$button}</div>");
                     };
                 });
             }
             $fieldset->control('input:file', 'image')->label($hasImage ? 'Replace Image(s)' : 'Image');
             $fieldset->control('input:text', 'title')->attributes(['placeholder' => 'Enter the step title']);
             $fieldset->control('input:textarea', 'description')->attributes(['placeholder' => 'Enter the step description']);
         });
     });
 }