96 lines
1.8 KiB
PHP
Executable File
96 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 (str_starts_with($this->path, 'uploads/') && file_exists(public_path($this->path))) {
|
|
return asset($this->path);
|
|
}
|
|
|
|
return Storage::url($this->path);
|
|
}
|
|
|
|
return (string) 'image/no_screen.png';
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getPathThumb(): string
|
|
{
|
|
if (!empty($this->path_thumb)) {
|
|
if (str_starts_with($this->path_thumb, 'uploads/') && file_exists(public_path($this->path_thumb))) {
|
|
return asset($this->path_thumb);
|
|
}
|
|
|
|
return Storage::url($this->path_thumb);
|
|
}
|
|
|
|
return (string) 'image/no_screen_thumb.png';
|
|
}
|
|
|
|
/**
|
|
* @return float
|
|
*/
|
|
public function getSize(): float
|
|
{
|
|
return (float) $this->size;
|
|
}
|
|
|
|
}
|