89 lines
1.8 KiB
PHP
Executable File
89 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
/**
|
|
* Class Screen
|
|
*
|
|
* @property string|null $name
|
|
* @property string|null $path
|
|
* @property string|null $path_thumb
|
|
* @property float|null $size
|
|
*
|
|
* @mixin
|
|
*/
|
|
class Screen extends Model
|
|
{
|
|
public $timestamps = false;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'name', 'path', 'path_thumb', 'size', 'product_id', 'type'
|
|
];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'name' => 'string',
|
|
'path' => 'string',
|
|
'path_thumb' => 'string',
|
|
'size' => 'float',
|
|
'product_id' => 'integer',
|
|
'type' => 'string'
|
|
];
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getName(): string
|
|
{
|
|
return (string) $this->name;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getPath(): string
|
|
{
|
|
if (!empty($this->path)) {
|
|
if (in_array(config('filesystems.default'), ['s3', 'minio'])) {
|
|
return Storage::url($this->path);
|
|
}
|
|
return config('app.url') . '/' . $this->path;
|
|
}
|
|
|
|
return (string) 'image/no_screen.png';
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getPathThumb(): string
|
|
{
|
|
if (!empty($this->path_thumb)) {
|
|
if (in_array(config('filesystems.default'), ['s3', 'minio'])) {
|
|
return Storage::url($this->path_thumb);
|
|
}
|
|
return config('app.url') . '/' . $this->path_thumb;
|
|
}
|
|
|
|
return (string) 'image/no_screen_thumb.png';
|
|
}
|
|
|
|
/**
|
|
* @return float
|
|
*/
|
|
public function getSize(): float
|
|
{
|
|
return (float) $this->size;
|
|
}
|
|
|
|
}
|