40 lines
895 B
PHP
40 lines
895 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
class Promocion extends Model
|
|
{
|
|
protected $table = 'promociones';
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'fecha_inicio' => 'date',
|
|
'fecha_fin' => 'date',
|
|
];
|
|
|
|
public function planteles(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Plantel::class, 'plantel_promocion');
|
|
}
|
|
|
|
public function alumnos(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Alumno::class, 'alumno_promocion')
|
|
->withPivot(['enviado_at', 'status_envio', 'whatsapp_mensaje_id']);
|
|
}
|
|
|
|
public function isActiva(): bool
|
|
{
|
|
return $this->status === 'activo';
|
|
}
|
|
|
|
public function imagenUrl(): ?string
|
|
{
|
|
return $this->imagen ? asset('storage/' . $this->imagen) : null;
|
|
}
|
|
}
|