63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?php namespace App\Models;
|
|
/**
|
|
* @copyright (c) 2025 Notsoweb Software (https://notsoweb.com) - All Rights Reserved
|
|
*/
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Descripción
|
|
*
|
|
* @author Moisés Cortés C. <moises.cortes@notsoweb.com>
|
|
*
|
|
* @version 1.0.0
|
|
*/
|
|
class Packages extends Model
|
|
{
|
|
protected $fillable = [
|
|
'name',
|
|
'price',
|
|
'period',
|
|
'data_limit',
|
|
];
|
|
|
|
protected $casts = [
|
|
'name' => 'string',
|
|
'price' => 'float',
|
|
'period' => 'integer',
|
|
'data_limit' => 'integer',
|
|
];
|
|
|
|
// Relación con la tabla pivote
|
|
public function packSims()
|
|
{
|
|
return $this->hasMany(PackSim::class, 'package_id');
|
|
}
|
|
|
|
// Relación muchos a muchos con SIM cards
|
|
public function simCards()
|
|
{
|
|
return $this->belongsToMany(
|
|
SimCard::class,
|
|
'pack_sims',
|
|
'package_id',
|
|
'sim_card_id'
|
|
)->withPivot('activated_at', 'deactivated_at', 'is_active')
|
|
->withTimestamps();
|
|
}
|
|
|
|
// SIM cards activas con este paquete
|
|
public function activeSimCards()
|
|
{
|
|
return $this->belongsToMany(
|
|
SimCard::class,
|
|
'pack_sims',
|
|
'package_id',
|
|
'sim_card_id'
|
|
)->wherePivot('is_active', true)
|
|
->withPivot('activated_at', 'deactivated_at', 'is_active')
|
|
->withTimestamps();
|
|
}
|
|
}
|