mivita/app/Models/UserShop.php
2019-01-06 01:40:44 +01:00

98 lines
No EOL
2.5 KiB
PHP

<?php
namespace App\Models;
use App\Http\Controllers\Api\KasController;
use Carbon\Carbon;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class UserShop extends Model
{
protected $table = 'user_shops';
protected $is_online = NULL;
protected $casts = [
'trans_title' => 'array',
'trans_copy' => 'array',
'trans_info' => 'array',
'featured' => 'array',
];
protected $fillable = [
'user_id', 'name', 'active', 'active_date',
];
use SoftDeletes;
protected $dates = ['deleted_at'];
use Sluggable;
public function sluggable()
{
return [
'slug' => [
'source' => 'name'
]
];
}
public function user()
{
return $this->belongsTo('App\User', 'user_id');
}
public function getActiveDateFormat(){
if(!$this->attributes['active_date']){ return ""; }
return Carbon::parse($this->attributes['active_date'])->format(\Util::formatDateTimeDB());
}
public function getSubdomain()
{
return config('app.protocol').$this->attributes['slug'].".".config('app.domain');
}
public function getSubdomainStatus()
{
if($this->is_online !== NULL){
return $this->is_online;
}
$kas = new KasController();
$domain = 'mivita.care';
$pra = array(
'subdomain_name' => $this->attributes['slug'].".".$domain,
'domain_name' => $this->attributes['slug'].".".$domain,
);
//check if exisist
$subdomain = $kas->action('get_subdomains', $pra);
if(!empty($subdomain[0]['is_active']) && $subdomain[0]['is_active'] == 'Y'){
$this->is_online = true;
return true;
}
$this->is_online = false;
return false;
}
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;
}
}