Files
backend-mm/app/Models/Ecommerce/Product/Property/AttributeValue.php
2025-09-25 03:03:31 +05:00

66 lines
1.4 KiB
PHP

<?php
namespace App\Models\Ecommerce\Product\Property;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
use Spatie\Translatable\HasTranslations;
class AttributeValue extends Model implements Sortable
{
use HasFactory;
use HasSlug;
use HasTranslations;
use SortableTrait;
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'value',
'key',
'attribute_id',
];
/**
* Translatable fields
*
* @var array<string>
*/
public $translatable = ['value'];
/**
* Translatable fields
*
* @var array<string, mixed>
*/
public $sortable = [
'order_column_name' => 'sort_order',
'sort_when_creating' => true,
];
/**
* Get the options for generating the slug.
*/
public function getSlugOptions(): SlugOptions
{
return SlugOptions::create()
->generateSlugsFrom('name')
->usingSeparator('_')
->saveSlugsTo('key');
}
/**
* Attribute
*/
public function attribute(): BelongsTo
{
return $this->belongsTo(Attribute::class, 'attribute_id');
}
}