/** * Deletes the specified computer type. * * @param int|string $id * * @return \Illuminate\Http\RedirectResponse */ public function destroy($id) { $type = $this->type->findOrFail($id); if ($type->delete()) { flash()->success('Success!', 'Successfully deleted computer type.'); return redirect()->route('computer-types.index'); } flash()->error('Error!', 'There was an issue deleting this computer type. Please try again.'); return redirect()->route('computer-types.index'); }
/** * Execute the job. * * @return Computer|bool */ public function handle() { $this->computer->os_id = OperatingSystem::findOrFail($this->request->input('os'))->id; $this->computer->type_id = ComputerType::findOrFail($this->request->input('type'))->id; $this->computer->name = $this->request->input('name'); $this->computer->ip = $this->request->input('ip'); $this->computer->model = $this->request->input('model'); $this->computer->description = $this->request->input('description'); if ($this->computer->save()) { return $this->computer; } return false; }
/** * 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); } }); }); }
/** * Run the database seeds. * * @return void */ public function run() { foreach ($this->types as $name) { ComputerType::firstOrCreate(compact('name')); } }
/** * Execute the job. * * @return bool */ public function handle() { $this->type->name = $this->request->input('name'); return $this->type->save(); }
/** * Creates a computer type. * * @return ComputerType */ public function handle() { $name = $this->name; return ComputerType::firstOrCreate(compact('name')); }