<?php namespace Modules\Admin\App\Models\Sat; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; class CodigoPostal extends Model { /** * The table associated with the model. * * @var string */ protected $table = 'sat_codigo_postal'; /** * The attributes that are mass assignable. * * @var string[] */ protected $fillable = [ 'c_codigo_postal', 'c_estado', 'c_municipio', 'c_localidad', 'estimulo_franja_fronteriza', 'fecha_inicio_de_vigencia', 'fecha_fin_de_vigencia', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'fecha_inicio_de_vigencia' => 'datetime', 'fecha_fin_de_vigencia' => 'datetime', ]; /** * Get the estado associated with the CodigoPostal. */ public function estado(): HasOne { return $this->hasOne(Estado::class, 'c_estado', 'c_estado'); } /** * Get the municipio associated with the CodigoPostal. */ public function municipio(): HasOne { return $this->hasOne(Municipio::class, 'c_municipio', 'c_municipio') ->where('c_estado', $this->c_estado); } /** * Get the localidad associated with the CodigoPostal. */ public function localidad(): HasOne { return $this->hasOne(Localidad::class, 'c_estado', 'c_estado') ->where('c_localidad', $this->c_localidad); } /** * Get the localidad associated with the CodigoPostal. */ public function colonias(): HasMany { return $this->hasMany(Colonia::class, 'c_codigo_postal', 'c_codigo_postal'); } }