store/app/Models/Product.php

37 lines
879 B
PHP

<?php
namespace App\Models;
use App\Models\Concerns\InteractsWithActivityLog;
use Illuminate\Database\Eloquent\Attributes\Guarded;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Sluggable\Attributes\Sluggable;
#[Guarded(['id'])]
#[Sluggable(from: 'name', to: 'slug')]
class Product extends Model
{
use InteractsWithActivityLog;
use SoftDeletes;
protected function casts(): array
{
return [
'is_active' => 'boolean',
];
}
public function categories(): BelongsToMany
{
return $this->belongsToMany(Category::class, 'product_categories');
}
public function variants(): HasMany
{
return $this->hasMany(ProductVariant::class);
}
}