82 lines
1.5 KiB
PHP
Executable File
82 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
/**
|
|
* Class File
|
|
* @property string|null $name
|
|
* @property string|null $path
|
|
* @property string|null $path_thumb
|
|
* @property float|null $size
|
|
* @mixin Model
|
|
*/
|
|
class File extends Model
|
|
{
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'name', 'path', 'path_thumb', 'size'
|
|
];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'name' => 'string',
|
|
'path' => 'string',
|
|
'path_thumb' => 'string',
|
|
'size' => 'float'
|
|
];
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getName(): string
|
|
{
|
|
return (string) $this->name;
|
|
}
|
|
|
|
/**
|
|
* @return string|null
|
|
*/
|
|
public function getPath()
|
|
{
|
|
if (!empty($this->path)) {
|
|
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
|
|
return Storage::url($this->path);
|
|
}
|
|
return (string) $this->path;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return string|null
|
|
*/
|
|
public function getPathThumb()
|
|
{
|
|
if (!empty($this->path_thumb)) {
|
|
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
|
|
return Storage::url($this->path_thumb);
|
|
}
|
|
return (string) $this->path_thumb;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return float
|
|
*/
|
|
public function getSize(): float
|
|
{
|
|
return (float) $this->size;
|
|
}
|
|
}
|