51 lines
1016 B
PHP
51 lines
1016 B
PHP
<?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');
|
|
}
|
|
}
|