2022-03-05 16:02:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2022-10-04 05:35:46 +02:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2022-03-05 16:02:12 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2022-05-15 04:01:48 +02:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
2022-10-04 05:35:46 +02:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2022-03-05 16:02:12 +01:00
|
|
|
|
|
|
|
class Shared extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
public $table = 'shared_hosting';
|
|
|
|
|
2022-07-22 15:49:18 +02:00
|
|
|
protected $keyType = 'string';
|
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
protected $fillable = ['id', 'active', 'main_domain', 'has_dedicated_ip', 'ip', 'shared_type', 'provider_id', 'location_id', 'bandwidth', 'disk', 'disk_type', 'disk_as_gb', 'domains_limit', 'subdomains_limit', 'ftp_limit', 'email_limit', 'db_limit', 'was_promo', 'owned_since'];
|
|
|
|
|
|
|
|
public $incrementing = false;
|
2022-05-15 04:01:48 +02:00
|
|
|
|
2022-10-04 05:35:46 +02:00
|
|
|
protected static function boot()
|
|
|
|
{
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
static::addGlobalScope('order', function (Builder $builder) {
|
|
|
|
$array = Settings::orderByProcess(Session::get('sort_on'));
|
|
|
|
if (!in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) {
|
|
|
|
$builder->orderBy($array[0], $array[1]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-19 07:21:13 +02:00
|
|
|
public static function allSharedHosting()
|
|
|
|
{//All shared hosting and relationships (no using joins)
|
|
|
|
return Cache::remember("all_shared", now()->addMonth(1), function () {
|
|
|
|
return Shared::with(['location', 'provider', 'price', 'ips', 'labels', 'labels.label'])->get();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function sharedHosting(string $shared_id)
|
|
|
|
{//Single shared hosting and relationships (no using joins)
|
|
|
|
return Cache::remember("shared_hosting.$shared_id", now()->addMonth(1), function () use ($shared_id) {
|
|
|
|
return Shared::where('id', $shared_id)
|
2022-09-22 05:20:23 +02:00
|
|
|
->with(['location', 'provider', 'price', 'ips', 'labels', 'labels.label'])->first();
|
2022-07-19 07:21:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ips()
|
2022-05-15 04:01:48 +02:00
|
|
|
{
|
2022-07-19 07:21:13 +02:00
|
|
|
return $this->hasMany(IPs::class, 'service_id', 'id');
|
2022-05-15 04:01:48 +02:00
|
|
|
}
|
|
|
|
|
2022-07-19 07:21:13 +02:00
|
|
|
public function location()
|
2022-05-15 04:01:48 +02:00
|
|
|
{
|
2022-07-19 07:21:13 +02:00
|
|
|
return $this->hasOne(Locations::class, 'id', 'location_id');
|
2022-05-15 04:01:48 +02:00
|
|
|
}
|
|
|
|
|
2022-07-19 07:21:13 +02:00
|
|
|
public function provider()
|
2022-05-15 04:01:48 +02:00
|
|
|
{
|
2022-07-19 07:21:13 +02:00
|
|
|
return $this->hasOne(Providers::class, 'id', 'provider_id');
|
2022-05-15 04:01:48 +02:00
|
|
|
}
|
2022-07-19 07:21:13 +02:00
|
|
|
|
|
|
|
public function price()
|
|
|
|
{
|
2022-10-04 05:35:46 +02:00
|
|
|
if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) {
|
|
|
|
return $this->hasOne(Pricing::class, 'service_id', 'id')->orderBy(Settings::orderByProcess(Session::get('sort_on'))[0], Settings::orderByProcess(Session::get('sort_on'))[1]);
|
|
|
|
}
|
2022-07-19 07:21:13 +02:00
|
|
|
return $this->hasOne(Pricing::class, 'service_id', 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function labels()
|
|
|
|
{
|
|
|
|
return $this->hasMany(LabelsAssigned::class, 'service_id', 'id');
|
|
|
|
}
|
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|