2020-10-27 01:49:52 +01:00
|
|
|
<?php namespace Aweos\Resizer\Models;
|
|
|
|
|
|
|
|
use Model;
|
|
|
|
use Storage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setting Model
|
|
|
|
*/
|
|
|
|
class Attachment extends Model
|
|
|
|
{
|
|
|
|
use \October\Rain\Database\Traits\Sluggable;
|
|
|
|
|
|
|
|
protected $slugs = ['slug' => 'title'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string The database table used by the model.
|
|
|
|
*/
|
|
|
|
public $table = 'responsive_attachments';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array Guarded fields
|
|
|
|
*/
|
|
|
|
protected $guarded = ['*'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array Fillable fields
|
|
|
|
*/
|
|
|
|
protected $fillable = ['id', 'file_id', 'title', 'slug', 'description'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array Relations
|
|
|
|
*/
|
|
|
|
public $hasOne = [];
|
|
|
|
public $hasMany = [];
|
|
|
|
public $belongsTo = [
|
|
|
|
'source' => [SourceFile::class, 'key' => 'file_id']
|
|
|
|
];
|
|
|
|
public $belongsToMany = [];
|
|
|
|
public $morphTo = [];
|
|
|
|
public $morphOne = [];
|
|
|
|
public $morphMany = [];
|
|
|
|
public $attachOne = [];
|
|
|
|
public $attachMany = [];
|
|
|
|
|
|
|
|
public function getFilenameAttribute() {
|
|
|
|
return $this->slug.'.'.$this->source->extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPathAttribute() {
|
|
|
|
return strtolower($this->slug[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getVersionPath($w) {
|
|
|
|
return $this->path.'/'.$this->slug.'-'.$w.'.'.$this->source->extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getVersionRegexAttribute() {
|
|
|
|
$path = preg_quote($this->path, '/');
|
|
|
|
$ext = preg_quote($this->source->extension, '/');
|
|
|
|
$name = preg_quote($this->slug, '/');
|
|
|
|
|
2020-10-28 23:25:57 +01:00
|
|
|
return "/^{$path}\/{$name}(-[0-9]+)?(-full)?\.{$ext}$/";
|
2020-10-27 01:49:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getUrlAttribute() {
|
|
|
|
return Storage::disk('uploads')->url($this->source->path);
|
|
|
|
}
|
|
|
|
}
|