From: Vincent Vanwaelscappel Date: Fri, 6 Mar 2020 14:57:56 +0000 (+0100) Subject: wip #3473 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=a5fd1686d755bac2e32cec5d2f02b74bd782a5aa;p=cubist_cms-back.git wip #3473 --- diff --git a/src/app/Magic/Controllers/CubistMagicController.php b/src/app/Magic/Controllers/CubistMagicController.php index 264a7e4..426787c 100644 --- a/src/app/Magic/Controllers/CubistMagicController.php +++ b/src/app/Magic/Controllers/CubistMagicController.php @@ -96,8 +96,6 @@ class CubistMagicController extends CubistCrudController */ $this->crud->addColumn(['name' => $model->getPrimaryKey(), 'type' => 'number', 'label' => "#", 'searchLogic' => 'text']); - $this->getModelInstance()->setupButtons($this->crud); - $this->updateFieldsFromModel($model); } diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 324fe91..5a6f1b1 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -604,6 +604,28 @@ class CubistMagicAbstractModel extends Model implements HasMedia 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) {