'array', 'bank' => 'array' ]; // protected $hidden = []; protected $dates = ['expires_at']; /* |-------------------------------------------------------------------------- | FUNCTIONS |-------------------------------------------------------------------------- */ public function preview(){ return ' Preview'; } // public function export_account(){ // return ' // // // // Export'; // } /* |-------------------------------------------------------------------------- | RELATIONS |-------------------------------------------------------------------------- */ public function profile():MorphTo { return $this->morphTo(); } public function country():BelongsTo { return $this->belongsTo(Country::class, 'country_id'); } public function clients():HasMany { return $this->hasMany(Client::class); } public function applications():HasMany { return $this->hasMany(Application::class); } public function last_application(){ return $this->applications()->latest()->first(); } public function broker_applications():HasMany { return $this->hasMany(BrokerApplication::class); } public function last_broker_application(){ return $this->broker_applications()->latest()->first(); } /* |-------------------------------------------------------------------------- | SCOPES |-------------------------------------------------------------------------- */ /* |-------------------------------------------------------------------------- | ACCESSORS |-------------------------------------------------------------------------- */ public function getTypeAndNameAttribute(){ return trans('app.account.filter.'.$this->type).' '.$this->profile->full_name; } public function getAccountTypeAttribute(){ return trans('app.account.filter.'.$this->type); } public function getCanApplyAttribute(){ return is_null($this->last_application()); } public function getCanExtendAttribute() { $month = Config::get('settings.legalization_extend') ?? 1; if($application = $this->last_application()){ return $application->state == 'approved' && $this->expires_at->lte(Carbon::now()->subMonths($month)); } return !empty($this->legalization_number) && !empty( $this->expires_at) && $this->expires_at->gte(Carbon::now()->subMonths($month)); } public function getApplicationStatusAttribute(){ $application = $this->last_application(); return $application->state ?? null; } public function getCountryNameAttribute(){ return $this->country->name; } public function getCanApplyBrokerAttribute(){ return is_null($this->last_application()); } public function getCanExtendBrokerAttribute() { $month = Config::get('settings.legalization_extend') ?? 1; if($application = $this->last_broker_application()){ return $application->state == 'approved' && $this->expires_at->lte(Carbon::now()->subMonths($month)); } return !empty($this->legalization_number) && !empty( $this->expires_at) && $this->expires_at->gte(Carbon::now()->subMonths($month)); } public function getApplicationBrokerStatusAttribute(){ $application = $this->last_broker_application(); return $application->state ?? null; } /* |-------------------------------------------------------------------------- | MUTATORS |-------------------------------------------------------------------------- */ }