80 lines
1.6 KiB
PHP
Executable File
80 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\LogOptionsTrait;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
|
|
/**
|
|
* Class Brend
|
|
* @property string|null $name
|
|
* @property string|null $image
|
|
* @property integer|null $id
|
|
* @mixin Model
|
|
*/
|
|
class Brand extends Model
|
|
{
|
|
use LogsActivity, LogOptionsTrait;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'image',
|
|
'slug',
|
|
"position",
|
|
];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'name' => 'array',
|
|
'image' => 'string'
|
|
];
|
|
|
|
protected static $logName = 'brand';
|
|
protected static $logAttributes = ['name'];
|
|
protected static $submitEmptyLogs = false;
|
|
protected static $logOnlyDirty = true;
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getID(): int
|
|
{
|
|
return (int) $this->id;
|
|
}
|
|
|
|
public function getName()
|
|
{
|
|
return $this->name[App::getLocale()] ?? null;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getImage(): string
|
|
{
|
|
if (!empty($this->image)) {
|
|
if (in_array(config('filesystems.default'), ['s3', 'minio'])) {
|
|
return rtrim(config('filesystems.disks.s3.url'), '/') . '/' . ltrim($this->image, '/');
|
|
}
|
|
|
|
return (string) '/' . $this->image;
|
|
}
|
|
|
|
return (string) 'images/no_brend.png';
|
|
}
|
|
|
|
public function categories()
|
|
{
|
|
return $this->belongsToMany(Category::class, 'categories_brands');
|
|
}
|
|
}
|