107 lines
2.3 KiB
PHP
107 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Cadastro\Localizacao;
|
|
|
|
use App\Models\ExameImagem\Agendamento\Agendamento;
|
|
use App\Models\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Endereco extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'cadastro_endereco';
|
|
|
|
protected $fillable = [
|
|
'logradouro_id',
|
|
'numero',
|
|
'complemento',
|
|
'referencia',
|
|
'loteamento_id',
|
|
'zona_id',
|
|
'latitude',
|
|
'longitude',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'created_at',
|
|
'created_lotacao_id',
|
|
'created_centro_custo_id',
|
|
'updated_at',
|
|
'updated_lotacao_id',
|
|
'updated_centro_custo_id',
|
|
'deleted_at',
|
|
'deleted_lotacao_id',
|
|
'deleted_centro_custo_id',
|
|
'logradouro_id',
|
|
'loteamento_id',
|
|
'zona_id',
|
|
];
|
|
|
|
protected $appends = [
|
|
'sem_numero',
|
|
'completo',
|
|
];
|
|
|
|
protected $with = [
|
|
'logradouro',
|
|
'loteamento',
|
|
'zona',
|
|
];
|
|
|
|
public function logradouro()
|
|
{
|
|
return $this->belongsTo(Logradouro::class);
|
|
}
|
|
|
|
public function loteamento()
|
|
{
|
|
return $this->belongsTo(Loteamento::class);
|
|
}
|
|
|
|
public function zona()
|
|
{
|
|
return $this->belongsTo(Zona::class);
|
|
}
|
|
|
|
public function infraestruturas()
|
|
{
|
|
return $this->hasMany(Infraestrutura::class);
|
|
}
|
|
|
|
public function domicilios()
|
|
{
|
|
return $this->hasMany(Domicilio::class);
|
|
}
|
|
|
|
public function agendamentosExameImagem()
|
|
{
|
|
return $this->hasMany(Agendamento::class);
|
|
}
|
|
|
|
public function getSemNumeroAttribute()
|
|
{
|
|
return is_null($this->numero);
|
|
}
|
|
|
|
public function getCompletoAttribute()
|
|
{
|
|
$tipo = $this->logradouro->tipo->descricao;
|
|
$logradouro = $this->logradouro->nome;
|
|
$numero = $this->sem_numero ? 'S/N' : $this->numero;
|
|
$bairro = $this->logradouro->bairro->nome;
|
|
$municipio = $this->logradouro->municipio->nome;
|
|
$uf = $this->logradouro->municipio->estado->uf;
|
|
|
|
return "{$tipo} {$logradouro}, {$numero} - {$bairro}, {$municipio} - {$uf}";
|
|
}
|
|
|
|
public function getIsAllowedToDeleteAttribute()
|
|
{
|
|
return $this->hasNoOne([
|
|
'infraestruturas',
|
|
'domicilios',
|
|
]);
|
|
}
|
|
}
|