diff --git a/.styleci.yml b/.styleci.yml index 6fbd388..5142082 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,8 +1,4 @@ preset: laravel -enabled: - - alpha_ordered_imports - disabled: - - length_ordered_imports - self_accessor \ No newline at end of file diff --git a/src/Nova/Fields/CloudImage.php b/src/Nova/Fields/CloudImage.php new file mode 100644 index 0000000..90fe47e --- /dev/null +++ b/src/Nova/Fields/CloudImage.php @@ -0,0 +1,47 @@ +downloadResponseCallback = null; + + $this->resolveUsing(function ($image) { + return $image->exists ? $image : null; + }); + + $this->thumbnail(function () { + return $this->value ? $this->value->make()->maxDimension(50)->get() : null; + }); + + $this->preview(function () { + return $this->value ? $this->value->make()->maxDimension(400)->get() : null; + }); + + $this->store(function (Request $request, Model $model) { + $model->{$this->attribute}->replaceWith(Image::upload($request->file($this->attribute))); + + return true; + }); + + $this->delete(function (Request $request, $model) { + $model->{$this->attribute}->delete(); + + return true; + }); + } +}