/** * Set the order for the field * @param $command */ protected function setOrder($command) { $command->order = 1; $lastField = FieldModel::where('entity_id', $command->entity_id)->orderBy('order', 'DESC')->first(); if (!is_null($lastField)) { $command->order = $lastField->order + 1; } return $command; }