/** * Returns a new form for computers. * * @param Computer $computer * * @return \Orchestra\Contracts\Html\Builder */ public function form(Computer $computer) { return $this->form->of('computers', function (FormGrid $form) use($computer) { $operatingSystems = OperatingSystem::all()->pluck('name', 'id'); $types = ComputerType::all()->pluck('name', 'id'); if ($computer->exists) { $method = 'PATCH'; $url = route('computers.update', [$computer->id]); $form->submit = 'Save'; } else { $method = 'POST'; $url = route('computers.store'); $form->submit = 'Create'; } $form->with($computer); $form->attributes(compact('method', 'url')); $form->fieldset(function (Fieldset $fieldset) use($computer, $operatingSystems, $types) { $fieldset->control('input:text', 'name')->label('Name')->attributes(['placeholder' => 'Name']); $fieldset->control('input:text', 'ip')->label('IP Address')->attributes(['placeholder' => '10.0.0.XXX']); $fieldset->control('select', 'os')->label('Operating System')->options($operatingSystems)->value(function (Computer $computer) { if ($computer->os instanceof OperatingSystem) { return $computer->os->id; } })->attributes(['class' => 'form-control', 'placeholder' => 'Select An Operating System']); $fieldset->control('select', 'type')->label('Type')->options($types)->value(function (Computer $computer) { if ($computer->type instanceof ComputerType) { return $computer->type->id; } })->attributes(['class' => 'form-control', 'placeholder' => 'Select a Type']); $fieldset->control('input:text', 'model')->label('Model')->attributes(['placeholder' => 'Model']); $fieldset->control('input:textarea', 'description')->label('Description')->attributes(['placeholder' => 'Description']); if (!$computer->exists) { // We'll only allow the exists in active directory checkbox if // the computer hasn't been created yet. This is due to // the access panel and can be updated there. $fieldset->control('input:checkbox', 'Exists in Active Directory?')->attributes(['class' => 'switch-mark'])->name('active_directory')->value(1); } }); }); }