oc-resizer-plugin/models/SourceFile.php

69 lines
1.6 KiB
PHP
Raw Normal View History

2020-10-27 01:49:52 +01:00
<?php namespace Aweos\Resizer\Models;
use Model;
2020-10-28 01:28:36 +01:00
use Storage;
2020-10-27 01:49:52 +01:00
/**
* Setting Model
*/
class SourceFile extends Model
{
use \October\Rain\Database\Traits\Sluggable;
protected $slugs = ['slug' => 'basename'];
2020-10-29 22:25:28 +01:00
public static $croppableTypes = [ 'image/jpeg', 'image/gif', 'image/png', 'image/webp' ];
2020-10-27 01:49:52 +01:00
/**
* @var string The database table used by the model.
*/
public $table = 'responsive_source_files';
/**
* @var array Guarded fields
*/
protected $guarded = ['*'];
/**
* @var array Fillable fields
*/
2020-10-27 02:22:40 +01:00
protected $fillable = ['id', 'basename', 'extension', 'tags', 'slug', 'aspect_ratio', 'min_width'];
2020-10-27 01:49:52 +01:00
2020-10-27 02:18:30 +01:00
public $jsonable = ['tags', 'aspect_ratio'];
2020-10-27 01:49:52 +01:00
/**
* @var array Relations
*/
public $hasOne = [];
public $hasMany = [
'attachments' => [Attachment::class, 'key' => 'file_id']
];
public $belongsTo = [];
public $belongsToMany = [];
public $morphTo = [];
public $morphOne = [];
public $morphMany = [];
public $attachOne = [];
public $attachMany = [];
public function getPathAttribute() {
return 'source/'.$this->slug.'.'.$this->extension;
}
2020-10-28 01:28:36 +01:00
public function getUrlAttribute() {
return Storage::disk('uploads')->url($this->path);
}
public function getTypeAttribute() {
return Storage::disk('uploads')->mimeType($this->path);
}
public function getSizeAttribute() {
return Storage::disk('uploads')->size($this->path);
}
public function isCroppable(): bool {
2020-10-29 22:25:28 +01:00
return in_array($this->type, static::$croppableTypes);
}
2020-10-27 01:49:52 +01:00
}