File: /var/www/api.ayokah.co.uk/app/Models/Category.php
<?php
namespace App\Models;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Category extends Model
{
use HasFactory;
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
if (empty($model->uuid)) {
$model->uuid = (string) Str::uuid();
}
});
}
protected $keyType = 'string';
public $incrementing = true;
protected $fillable = ['name', 'parent_id', 'slug', 'description', 'feature_image', 'icon', 'type', 'uuid'];
protected $table = 'categories';
public function products()
{
return $this->hasMany(Product::class);
}
public function parent()
{
return $this->belongsTo(Category::class, 'parent_id');
}
public function children()
{
return $this->hasMany(Category::class, 'parent_id');
}
public function seller()
{
return $this->hasMany(Seller::class);
}
}