File manager - Edit - /var/www/html/portal/app/Models/Empresa.php
Back
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; use Illuminate\Support\Str; use DateTimeInterface; class Empresa extends Model { use HasApiTokens, HasFactory, Notifiable; protected $connection = 'mysql'; public $incrementing = false; protected $keyType = 'string'; protected $table = 'empresas'; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; protected $fillable = [ 'id', 'created_at', 'updated_at', 'razaoSocial', 'nomeFantasia', 'numeroInscricaoMunicipal', 'cadastur', 'cnpj', 'anoAbertura', 'principalAtividade', 'owner_id', 'endereco_id', 'responsavel_id', 'preposto_id', 'telefone', 'celular', 'possui_whatsapp', 'email', 'site', 'contratoSocial', 'contratoSocialLink', 'cartaoCNPJ', 'cartaoCNPJLink', 'registroJuntaComercial', 'registroJuntaComercialLink', 'alvaraDeFuncionamento', 'alvaraDeFuncionamentoLink', 'inscricaoEstadual', 'inscricaoEstadualLink', 'inscricaoMunicipal', 'inscricaoMunicipalLink', 'status', ]; protected $casts = [ 'possui_whatsapp' => 'boolean', ]; public function getTelefoneAttribute($value): ?string { if (!$value) { return null; } // Remove tudo que não for número $telefone = preg_replace('/\D/', '', $value); if (strlen($telefone) === 11) { // Celular return preg_replace( '/(\d{2})(\d{5})(\d{4})/', '($1) $2-$3', $telefone ); } if (strlen($telefone) === 10) { // Fixo return preg_replace( '/(\d{2})(\d{4})(\d{4})/', '($1) $2-$3', $telefone ); } // Caso venha algo inesperado return $value; } public function getCelularAttribute($value): ?string { if (!$value) { return null; } $celular = preg_replace('/\D/', '', $value); if (strlen($celular) === 11) { return preg_replace( '/(\d{2})(\d{5})(\d{4})/', '($1) $2-$3', $celular ); } return $value; } /** * URL wa.me para contato via WhatsApp no celular da empresa (formato Brasil). */ public function getCelularWhatsappUrlAttribute(): ?string { $celular = $this->celular; if (!$celular) { return null; } $digits = preg_replace('/\D/', '', (string) $celular); if ($digits === '') { return null; } if (str_starts_with($digits, '0')) { $digits = substr($digits, 1); } if (str_starts_with($digits, '55') && strlen($digits) >= 12 && strlen($digits) <= 13) { $normalized = $digits; } elseif (strlen($digits) === 11 || strlen($digits) === 10) { $normalized = '55' . $digits; } else { return null; } return 'https://wa.me/' . $normalized; } public function onibusPorEmpresa() { return $this->hasMany(\App\Models\TurisAngra\FluxoDeOnibus\OnibusTurismo::class, 'empresa_id', 'id'); } public function onibusTurismo() { return $this->belongsTo(\App\Models\TurisAngra\FluxoDeOnibus\OnibusTurismo::class, 'empresa_id', 'id'); } public function user() { return $this->belongsTo(User::class, 'owner_id', 'id'); } public function responsavel() { return $this->belongsTo(User::class, 'responsavel_id', 'id'); } public function preposto() { return $this->belongsTo(User::class, 'preposto_id', 'id'); } public function endereco() { return $this->belongsTo(Endereco::class, 'endereco_id', 'id'); } public static function boot() { parent::boot(); static::creating(function ($model) { $model->id = Str::uuid(); }); } public function getCnpjAttribute($value) { if (strlen($value) === 14) { return substr($value, 0, 2) . '.' . substr($value, 2, 3) . '.' . substr($value, 5, 3) . '/' . substr($value, 8, 4) . '-' . substr($value, 12, 2); } return $value; } public function setCnpjAttribute($value) { $this->attributes['cnpj'] = preg_replace('/\D/', '', $value); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.1 |
proxy
|
phpinfo
|
Settings