/** * Returns a new form for the specified work order attachment. * * @param WorkOrder $workOrder * @param Attachment $attachment * * @return \Orchestra\Contracts\Html\Builder */ public function form(WorkOrder $workOrder, Attachment $attachment) { return $this->form->of('work-orders.attachments', function (FormGrid $form) use($workOrder, $attachment) { $files = true; if ($attachment->exists) { $url = route('maintenance.work-orders.attachments.update', [$workOrder->getKey(), $attachment->getKey()]); $method = 'PATCH'; $form->submit = 'Save'; $form->with($attachment); } else { $url = route('maintenance.work-orders.attachments.store', [$workOrder->getKey()]); $method = 'POST'; $form->submit = 'Upload'; } $form->attributes(compact('url', 'method', 'files')); $form->fieldset(function (Fieldset $fieldset) use($attachment) { if ($attachment->exists) { // If the attachment exists we'll provide the ability // to only change the attachments name. $fieldset->control('input:text', 'name')->label('Attachment Name'); } else { // Otherwise we'll allow the user to upload multiple // attachments at once for the specified work order. $fieldset->control('input:file', 'files[]')->label('Files')->attributes(['multiple' => true]); } }); }); }