ContactInfo.php
1 <?php 2 3 namespace App\Models; 4 5 use Attribute; 6 use Illuminate\Database\Eloquent\Casts\Attribute as CastsAttribute; 7 use Illuminate\Database\Eloquent\Factories\HasFactory; 8 use Illuminate\Database\Eloquent\Model; 9 use Illuminate\Database\Eloquent\Relations\BelongsTo; 10 use Illuminate\Database\Eloquent\Relations\MorphMany; 11 use Illuminate\Database\Eloquent\Relations\MorphTo; 12 use Illuminate\Database\Eloquent\Relations\MorphToMany; 13 14 class ContactInfo extends Model 15 { 16 use HasFactory; 17 18 protected $fillable = [ 19 'address', 20 'city', 21 'postal_code', 22 'phone', 23 'email', 24 'country_id', 25 'dossier_id' 26 ]; 27 28 public function fullAddress(): CastsAttribute 29 { 30 return new CastsAttribute( 31 get: function () { 32 return $this->address . ', ' . $this->city . ', ' . $this->postal_code . ', ' . $this->country?->name; 33 }, 34 ); 35 } 36 37 public function contactable(): MorphTo 38 { 39 return $this->morphTo(); 40 } 41 42 public function country(): BelongsTo 43 { 44 return $this->belongsTo(Country::class, 'country_id'); 45 } 46 }