49 lines
922 B
PHP
49 lines
922 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\Multitenantable;
|
|
use DateTimeInterface;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Category extends Model
|
|
{
|
|
use Multitenantable;
|
|
|
|
public $primaryKey = 'uuid';
|
|
|
|
public $incrementing = false;
|
|
|
|
public $keyType = 'string';
|
|
|
|
public $imageFields = ['server_image_url'];
|
|
|
|
protected $fillable = [
|
|
'uuid',
|
|
'name',
|
|
'server_image_url'
|
|
];
|
|
|
|
protected $casts = [
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime'
|
|
];
|
|
|
|
protected function serializeDate(DateTimeInterface $date)
|
|
{
|
|
return $date->format('Y-m-d H:i:s');
|
|
}
|
|
|
|
public function products()
|
|
{
|
|
return $this->hasMany(Product::class, 'category_id', 'uuid');
|
|
}
|
|
|
|
public function getServerImageUrlAttribute($value)
|
|
{
|
|
if (!$value) return null;
|
|
|
|
return asset('storage/' . $value);
|
|
}
|
|
}
|