This commit is contained in:
pbao9
2026-02-06 20:52:59 +07:00
parent d7aadf7544
commit e7b9ce7485
17 changed files with 570 additions and 36 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ControlPanel extends Model
{
use HasFactory;
protected $fillable = [
'name',
'slug',
'logo',
'description',
'is_active',
'sort_order',
];
protected $casts = [
'is_active' => 'boolean',
];
/**
* Relationship: Control Panel có nhiều Products (Hosting)
*/
public function products()
{
return $this->belongsToMany(Product::class, 'product_control_panel')
->withPivot(['price_modifier', 'is_default'])
->withTimestamps();
}
/**
* Scope: Chỉ lấy active panels
*/
public function scopeActive($query)
{
return $query->where('is_active', true);
}
/**
* Scope: Sắp xếp theo sort_order
*/
public function scopeOrdered($query)
{
return $query->orderBy('sort_order', 'asc');
}
}
+13
View File
@@ -19,6 +19,8 @@ class Product extends Model
'slug',
'short_description',
'description',
'thumbnail',
'gallery',
'setup_fee',
'trial_days',
'cpu',
@@ -39,6 +41,7 @@ class Product extends Model
'is_active' => 'boolean',
'is_unlimited' => 'boolean',
'published_at' => 'date',
'gallery' => 'array',
];
/**
@@ -58,6 +61,16 @@ class Product extends Model
->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
*/