90 lines
2.1 KiB
PHP
90 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\HasUuid;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Product extends Model
|
|
{
|
|
use HasFactory, HasUuid, SoftDeletes;
|
|
|
|
protected array $uuidColumns = ['uuid'];
|
|
protected string $slugColumn = 'name';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'slug',
|
|
'short_description',
|
|
'description',
|
|
'thumbnail',
|
|
'gallery',
|
|
'setup_fee',
|
|
'trial_days',
|
|
'cpu',
|
|
'ram',
|
|
'gpu',
|
|
'disk',
|
|
'bandwidth',
|
|
'stock',
|
|
'is_unlimited',
|
|
'is_active',
|
|
'sort_order',
|
|
'product_type',
|
|
'product_categories_id',
|
|
'published_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
'is_unlimited' => 'boolean',
|
|
'published_at' => 'date',
|
|
'gallery' => 'array',
|
|
];
|
|
|
|
/**
|
|
* Relationship: Product belongs to a Category
|
|
*/
|
|
public function category()
|
|
{
|
|
return $this->belongsTo(ProductCategories::class, 'product_categories_id');
|
|
}
|
|
|
|
/**
|
|
* Relationship: Product has many OS versions (pivot table: os_product)
|
|
*/
|
|
public function osVersions()
|
|
{
|
|
return $this->belongsToMany(Os::class, 'os_product', 'product_id', 'os_id')
|
|
->withTimestamps();
|
|
}
|
|
|
|
/**
|
|
* Relationship: Product has many Control Panels (for Hosting)
|
|
*/
|
|
public function controlPanels()
|
|
{
|
|
return $this->belongsToMany(ControlPanel::class, 'product_control_panel')
|
|
->withPivot(['price_modifier', 'is_default'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
/**
|
|
* Relationship: Product has many pricings
|
|
*/
|
|
public function pricings()
|
|
{
|
|
return $this->hasMany(ProductPricings::class, 'product_id');
|
|
}
|
|
|
|
/**
|
|
* Legacy: Many-to-many categories (if still needed)
|
|
*/
|
|
public function categories()
|
|
{
|
|
return $this->belongsToMany(ProductCategories::class, 'product_product_category', 'product_id', 'product_category_id');
|
|
}
|
|
}
|