Files
getgreen-backend/app/Models/Brand.php
2026-04-28 15:02:06 +05:00

76 lines
1.4 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)) {
return Storage::url($this->image);
}
return (string) 'images/no_brend.png';
}
public function categories()
{
return $this->belongsToMany(Category::class, 'categories_brands');
}
}