/**
  * Return the unique label.
  *
  * @param string $size
  * @return null|string
  */
 protected function uniqueLabel($size = 'sm')
 {
     if ($this->object->isUnique()) {
         return '<span class="label label-primary label-' . $size . '">' . trans('streams::assignment.unique.name') . '</span>';
     }
     return null;
 }
 /**
  * Add the field type column.
  *
  * @param Blueprint           $table
  * @param AssignmentInterface $assignment
  */
 public function addColumn(Blueprint $table, AssignmentInterface $assignment)
 {
     // Skip if the column already exists.
     if ($this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName() . '_id')) {
         return;
     }
     $table->string($this->fieldType->getColumnName() . '_type')->nullable(!$assignment->isRequired());
     $table->integer($this->fieldType->getColumnName() . '_id')->nullable(!$assignment->isRequired());
     if ($assignment->isUnique() && $assignment->isTranslatable()) {
         $table->unique([$this->fieldType->getColumnName() . '_type', $this->fieldType->getColumnName() . '_id']);
     }
 }
 /**
  * Parse the assignment rules.
  *
  * @param StreamInterface     $stream
  * @param AssignmentInterface $assignment
  * @param                     $string
  */
 protected function parseAssignmentRules(StreamInterface $stream, AssignmentInterface $assignment, &$string)
 {
     $rules = [];
     if ($assignment->isRequired()) {
         $rules[] = 'required';
     }
     if ($assignment->isUnique()) {
         $rules[] = 'unique:' . $stream->getEntryTableName() . ',' . $assignment->getColumnName();
     }
     if (is_array($rules)) {
         $rules = implode('|', array_filter($rules));
         $string .= "\n'{$assignment->getFieldSlug()}' => '{$rules}',";
     }
 }
 /**
  * @param Blueprint           $table
  * @param AssignmentInterface $assignment
  */
 public function addColumn(Blueprint $table, AssignmentInterface $assignment)
 {
     // Skip if the column already exists.
     if ($this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
         return;
     }
     /**
      * Add the column to the table.
      *
      * @var Blueprint|Fluent $column
      */
     $column = $table->{$this->fieldType->getColumnType()}($this->fieldType->getColumnName(), 11, array_get($this->fieldType->getConfig(), 'decimals', 2))->nullable(!$assignment->isTranslatable() ? !$assignment->isRequired() : true);
     if (!str_contains($this->fieldType->getColumnType(), ['text', 'blob'])) {
         $column->default(array_get($this->fieldType->getConfig(), 'default_value'));
     }
     // Mark the column unique if desired and not translatable.
     if ($assignment->isUnique() && !$assignment->isTranslatable()) {
         $table->unique($this->fieldType->getColumnName());
     }
 }
 /**
  * Update the field type column to the table.
  *
  * @param Blueprint           $table
  * @param AssignmentInterface $assignment
  */
 public function updateColumn(Blueprint $table, AssignmentInterface $assignment)
 {
     // Skip if no column type.
     if (!$this->fieldType->getColumnType()) {
         return;
     }
     // Skip if the column doesn't exists.
     if (!$this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
         return;
     }
     /**
      * Update the column to the table.
      *
      * @var Blueprint|Fluent $column
      */
     $column = call_user_func_array([$table, $this->fieldType->getColumnType()], array_filter([$this->fieldType->getColumnName(), $this->fieldType->getColumnLength()]));
     $column->nullable(!$assignment->isTranslatable() ? !$assignment->isRequired() : true)->change();
     if (!str_contains($this->fieldType->getColumnType(), ['text', 'blob'])) {
         $column->default(array_get($this->fieldType->getConfig(), 'default_value'));
     }
     /**
      * Mark the column unique if desired and not translatable.
      * Otherwise, drop the unique index.
      */
     $connection = $this->schema->getConnection();
     $manager = $connection->getDoctrineSchemaManager();
     $doctrine = $manager->listTableDetails($connection->getTablePrefix() . $table->getTable());
     // The unique index name.
     $unique = md5('unique_' . $this->fieldType->getColumnName());
     /**
      * If the assignment is unique and not translatable
      * and the table does not already have the given the
      * given table index then go ahead and add it.
      */
     if ($assignment->isUnique() && !$assignment->isTranslatable() && !$doctrine->hasIndex($unique)) {
         $table->unique($this->fieldType->getColumnName(), $unique);
     }
     /**
      * If the assignment is NOT unique and not translatable
      * and the table DOES have the given table index
      * then we need to remove.
      */
     if (!$assignment->isUnique() && !$assignment->isTranslatable() && $doctrine->hasIndex($unique)) {
         $column->dropIndex(md5('unique_' . $this->fieldType->getColumnName()));
     }
 }