*/
$this->crud->addColumn(['name' => $model->getPrimaryKey(), 'type' => 'number', 'label' => "#", 'searchLogic' => 'text']);
- $this->getModelInstance()->setupButtons($this->crud);
-
$this->updateFieldsFromModel($model);
}
return $f->filterValue($value);
}
+ /**
+ * @param string $fieldname
+ * @param string|\Symfony\Component\HttpFoundation\File\UploadedFile $filepath
+ * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded\DiskDoesNotExist
+ * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded\FileDoesNotExist
+ * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded\FileIsTooBig
+ */
+ public function addMediaToField($fieldname, $filepath)
+ {
+ $collection = $this->getAttribute($fieldname);
+ $save = false;
+ if (!$collection) {
+ $collection = substr(hash('sha256', uniqid($fieldname, true)), 0, 10);
+ $this->setAttribute($fieldname, $collection);
+ $save = true;
+ }
+ $this->addMedia($filepath)->toMediaCollection($collection);
+ if ($save) {
+ $this->save();
+ }
+ }
+
public function replicate(array $except = null)
{