This commit is contained in:
106
api/app/Models/Cadastro/Localizacao/Endereco.php
Normal file
106
api/app/Models/Cadastro/Localizacao/Endereco.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user