'array', 'trans' => 'array', ]; protected $fillable = [ 'user_id', 'name', 'active', 'active_date', ]; use SoftDeletes; protected $dates = ['deleted_at']; use Sluggable; public function sluggable(): array { return [ 'slug' => [ 'source' => 'name', ], ]; } public function user() { return $this->belongsTo('App\User', 'user_id'); } public function on_sites() { return $this->hasMany('App\Models\UserShopOnSite', 'user_shop_id', 'id'); } public function getActiveDateFormat() { if (! $this->attributes['active_date']) { return ''; } return Carbon::parse($this->attributes['active_date'])->format(\Util::formatDateTimeDB()); } public function getActiveDateFormatSmall() { if (! $this->attributes['active_date']) { return ''; } return Carbon::parse($this->attributes['active_date'])->format('d.m.Y'); } public function getLang($key, $default = true) { $lang = \App::getLocale(); if ($lang == 'de') { return $this->{$key}; } return $this->getTrans($key, $lang, $default); } public function getTrans($key, $lang, $default = true) { if ($lang == 'de') { return $this->{$key}; } if (! empty($this->trans[$lang][$key])) { return $this->trans[$lang][$key]; } if ($default) { return ! empty($this->{$key}) ? $this->{$key} : ''; } return ''; } public function getSubdomain($session = true) { if ($session && \Session::has('user_shop_domain')) { return \Session::get('user_shop_domain'); } return config('app.protocol').$this->attributes['slug'].'.'.config('app.domain').config('app.tld_care'); } public function getSubdomainAvailable() { $rCurlHandle = curl_init($this->attributes['slug'].'.mivita.care'); curl_setopt($rCurlHandle, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($rCurlHandle, CURLOPT_HEADER, true); curl_setopt($rCurlHandle, CURLOPT_NOBODY, true); curl_setopt($rCurlHandle, CURLOPT_RETURNTRANSFER, true); $strResponse = curl_exec($rCurlHandle); curl_close($rCurlHandle); if (! $strResponse) { return false; } $url = 'http://'.$this->attributes['slug'].'.mivita.care/domain/check'; if (@file_get_contents($url) != 'checked') { return false; } return true; } public function isImage() { if (empty($this->attributes['filename']) || @$this->attributes['filename'] == null || @$this->attributes['filename'] == '') { return false; } if (! \Storage::disk('public')->has('images/shop/'.$this->filename)) { return false; } return true; } public function getImage() { if ($this->isImage()) { $link = 'images/shop/'.$this->filename; return '/storage/'.$link.'?=lm='.\Storage::disk('public')->lastModified($link); } return false; } }