コード例 #1
0
 /**
  * Edit a command
  *
  * @param $id
  * @return mixed
  */
 public function postSchedule($id = null)
 {
     \ruler()->check($this->permission, ['id' => 'exists:schedule,schedule_id'], ['id' => $id]);
     $schedule = Schedule::findOrNew($id);
     // Form
     $form = \form()->enableRemote();
     $form->addText('schedule_id', 'ID')->setFilters('nowp|lower|alpha');
     $form->addText('command', 'Commande');
     $form->addTextarea('description', 'Description', false);
     $form->addText('schedule', 'Fréquence');
     $form->addBoolean('can_overlapping', 'Chevauchement');
     $form->addBoolean('is_active', 'Active');
     $form->addSubmit('Enregistrer');
     // Legende
     $form->setLegend($schedule->exists ? 'Commande : ' . $schedule->command : 'Ajouter une commande : ');
     // Traitement
     if (\request()->has('Enregistrer')) {
         $form->valid(\request()->all());
         if ($form->isValid()) {
             $data = $form->getFilteredValues();
             try {
                 if ($schedule->exists) {
                     $schedule->update($data);
                 } else {
                     $schedule::create($data);
                 }
                 \js()->success()->reloadDataTable()->closeRemoteModal();
             } catch (\Exception $e) {
                 \js()->error($e->getMessage());
             }
         }
     } elseif ($schedule->exists) {
         $form->populate($schedule->toArray());
     }
     return response()->modal($form);
 }