Edit File: Country.php
<?php namespace App\Models; use App\Traits\ModelTrait; use Illuminate\Database\Eloquent\Relations\HasMany; use Spatie\Translatable\HasTranslations; class Country extends BaseModel { use HasTranslations, ModelTrait; const IMAGEPATH = 'countries'; protected $fillable = ['name', 'key', 'flag']; public $translatable = ['name']; /** * Get the flag attribute. * @return string */ public function getFlagAttribute(): string { if ($this->attributes['flag']) { $flag = asset('admin/assets/flags/png/' . $this->attributes['flag']); } else { $flag = $this->defaultImage('users'); } return $flag; } /** * Get the flag attribute. * @return string */ public function myFlag(): string { return $this->attributes['flag']; } public function cities() { return $this->hasMany(City::class, 'country_id', 'id'); } public static function boot() { parent::boot(); static::deleting(function ($country) { if($country->cities()->exists()) { throw new \Exception(__('admin.this_country_has_cities_cannot_be_deleted')); } }); } }
Back to File Manager