Co-authored-by: Juan Felipe Zapata Moreno <zapata_pipe@hotmail.com> Reviewed-on: #1
61 lines
1.3 KiB
PHP
61 lines
1.3 KiB
PHP
<?php namespace App\Models;
|
|
/**
|
|
* @copyright (c) 2025 Notsoweb Software (https://notsoweb.com) - All Rights Reserved
|
|
*/
|
|
|
|
|
|
use App\Enums\SimCardStatus;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Modelo para tarjetas SIM
|
|
*
|
|
* @author Moisés Cortés C. <moises.cortes@notsoweb.com>
|
|
*
|
|
* @version 1.0.0
|
|
*/
|
|
class SimCard extends Model
|
|
{
|
|
protected $fillable = [
|
|
'iccid',
|
|
'msisdn',
|
|
'status',
|
|
];
|
|
|
|
protected $casts = [
|
|
'status' => SimCardStatus::class,
|
|
];
|
|
|
|
// Relación con la tabla pivote
|
|
public function packSims()
|
|
{
|
|
return $this->hasMany(PackSim::class, 'sim_card_id');
|
|
}
|
|
|
|
// Relación muchos a muchos con paquetes
|
|
public function packages()
|
|
{
|
|
return $this->belongsToMany(
|
|
Packages::class,
|
|
'pack_sims',
|
|
'sim_card_id',
|
|
'package_id'
|
|
)->withPivot('activated_at', 'deactivated_at', 'is_active')
|
|
->withTimestamps();
|
|
}
|
|
|
|
// Paquete actualmente activo
|
|
public function activePackage()
|
|
{
|
|
return $this->belongsToMany(
|
|
Packages::class,
|
|
'pack_sims',
|
|
'sim_card_id',
|
|
'package_id'
|
|
)->wherePivot('is_active', true)
|
|
->withPivot('activated_at', 'deactivated_at', 'is_active')
|
|
->withTimestamps()
|
|
->limit(1);
|
|
}
|
|
}
|