Skip to content

Commit

Permalink
Merge pull request #40 from makeabledk/feat/nova-field
Browse files Browse the repository at this point in the history
Feat/nova field
  • Loading branch information
larsrbak authored Nov 15, 2019
2 parents fe999d3 + 623f3a4 commit ee176d1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
4 changes: 0 additions & 4 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
preset: laravel

enabled:
- alpha_ordered_imports

disabled:
- length_ordered_imports
- self_accessor
47 changes: 47 additions & 0 deletions src/Nova/Fields/CloudImage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Makeable\CloudImages\Nova\Fields;

use Illuminate\Database\Eloquent\Model;
use Laravel\Nova\Fields\Image as ImageField;
use Makeable\CloudImages\Image;

class CloudImage extends ImageField
{
/**
* @param string $name
* @param string|null $attribute
* @return void
*/
public function __construct($name, $attribute = null)
{
parent::__construct($name, $attribute);

// Until we implement the download() properly
$this->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;
});
}
}

0 comments on commit ee176d1

Please sign in to comment.