Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Tamagawa committed May 26, 2017
1 parent d9c2b72 commit 0bc8cd1
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 53 deletions.
29 changes: 2 additions & 27 deletions src/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Category extends Model

protected $dates = ['deleted_at'];

protected $fillable = ['status', 'name', 'description', 'image', 'type'];
protected $fillable = ['status', 'name', 'description', 'type'];

public $translatable = ['name', 'description', 'slug'];

Expand All @@ -36,39 +36,14 @@ public function sluggable()

public function __construct(array $attributes = [])
{
$this->hasAttachedFile('image', [
'styles' => [
'crop' => function ($file, $imagine) {
$image = $imagine->open($file->getRealPath());
if (request()->input('crop.image.w', 0) > 0 && request()->input('crop.image.y', 0) > 0) {
$image->crop(new \Imagine\Image\Point(request()->input('crop.image.x'), request()->input('crop.image.y'))
, new \Imagine\Image\Box(request()->input('crop.image.w'), request()->input('crop.image.h')));
}
return $image;
}
],
/*'default_url' => '/assets/img/avatar.png',*/
]);

parent::__construct($attributes);
parent::__construct($attributes);
}

public static function boot()
{
parent::boot();

static::bootStapler();
}

public function toArray()
{
return array_merge(parent::toArray(), [
'image' => $this->attachedFiles['image']->url()
, 'image_crop' => $this->attachedFiles['image']->url('crop')
]);
}


public function scopeSort($query, $fields = [])
{
if (count($fields) <= 0) {
Expand Down
16 changes: 0 additions & 16 deletions src/config/mcategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,4 @@
'name' => 'Categorias'
, 'icon' => 'fa fa-align-left'
, 'order' => 50

/*
para desabilitar a imagem passe false como valor
, 'image' => false
para habilitar a imagem passe o array com o width e height
, 'image' => [
'width' => 640
, 'height' => 480
]
*/
, 'image' => [
'width' => 640
, 'height' => 480
]

];
10 changes: 0 additions & 10 deletions src/resources/views/admin/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@

{!! BootForm::text('name', 'Nome', null, ['data-rule-required' => true, 'maxlength' => '150']) !!}

@if (config('mcategories.image', true))
{!! BootForm::file('image', 'Imagem', [
'data-allowed-file-extensions' => '["jpg", "png"]',
'data-initial-preview' => '["<img src=\"' . $category->image->url('crop') . '\" class=\"file-preview-image\">"]',
'data-initial-caption' => $category->image->originalFilename(),
'data-min-image-width' => config('mcategories.image.width', 640),
'data-min-image-height' => config('mcategories.image.height', 480),
'data-aspect-ratio' => number_format(config('mcategories.image.width', 640)/config('mcategories.image.height', 480), 2)
]) !!}
@endif
</div>
</div>
</div>
Expand Down

0 comments on commit 0bc8cd1

Please sign in to comment.