'array', 'mail_dirs' => 'array', 'contact_emails' => 'array']; public $timestamps = false; public function travel_program_country() { return $this->hasOne('App\Models\TravelProgramCountry', 'country_id', 'id'); } public function feedback_page() { return $this->belongsTo('App\Models\Page', 'feedback_page_id', 'id'); } public function crm_travel_country() { return $this->belongsTo(\App\Models\Sym\TravelCountry::class, 'crm_id', 'id'); } public function travel_nationality_requirements() { return $this->hasMany('App\Models\TravelNationalityRequirement', 'travel_country_id', 'id'); } public function general_files() { return $this->hasMany(GeneralFile::class, 'travel_country_id', 'id'); } public function travel_country_services() { return $this->hasMany(TravelCountryService::class, 'travel_country_id', 'id')->orderBy('pos', 'DESC'); } public function setSlugAttribute( $value ) { if(!isset($value) || $value == ""){ $this->attributes['slug'] = Str::slug(pre_slug($this->name), '-'); }else{ $this->attributes['slug'] = Str::slug(pre_slug($value), '-'); } } public function getContactLandsArray(){ $ret = []; if($this->contact_lands){ foreach ($this->contact_lands as $contact_land_id){ $travel_country = TravelCountry::where('crm_id', $contact_land_id)->first(); if($travel_country){ $ret[] = $travel_country->name; } } } return $ret; } public function getMailDirs($id){ return isset($this->mail_dirs[$id]) ? $this->mail_dirs[$id] : []; } public function getContactLandsModels(){ $ret = []; if($this->contact_lands){ foreach ($this->contact_lands as $contact_land_id){ if($travel_country = TravelCountry::where('crm_id', $contact_land_id)->first()){ $ret[$travel_country->id] = $travel_country; } } }else{ $ret[$this->id] = $this; } return $ret; } public function getNationalityRequirement($travel_nationality_id){ $model = TravelNationalityRequirement::where('travel_country_id', $this->id)->where('travel_nationality_id', $travel_nationality_id)->first(); if($model){ return $model->text; } return ""; } public function setNationalityRequirement($travel_nationality_id, $text){ $model = TravelNationalityRequirement::where('travel_country_id', $this->id)->where('travel_nationality_id', $travel_nationality_id)->first(); if($model){ $model->text = $text; $model->save(); }else{ $data = [ 'travel_country_id' => $this->id, 'travel_nationality_id' => $travel_nationality_id, 'text' => $text, ]; TravelNationalityRequirement::create($data); } return ""; } public static function getAsNameIdArray($empty = true, $id = 'crm_id'){ $ret = TravelCountry::get()->pluck('name', $id)->toArray(); if($empty){ $first = [null => "-"]; return $first + $ret; } return $ret; } }