Updated order/sort by on index pages
Updated order/sort by on index pages As using the relationship for price related sorts does not work this method does
This commit is contained in:
parent
eda9d1b945
commit
beaf9af041
|
@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class Domains extends Model
|
||||
{
|
||||
|
@ -23,7 +24,12 @@ class Domains extends Model
|
|||
public static function allDomains()
|
||||
{//All domains and relationships (no using joins)
|
||||
return Cache::remember("all_domains", now()->addMonth(1), function () {
|
||||
return Domains::with(['provider', 'price', 'labels'])->get();
|
||||
$query = Domains::with(['provider', 'price', 'labels']);
|
||||
if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) {
|
||||
$options = Settings::orderByProcess(Session::get('sort_on'));
|
||||
$query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "domains.id"), $options[1]);
|
||||
}
|
||||
return $query->get();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,12 @@ class Misc extends Model
|
|||
public static function allMisc()
|
||||
{//All misc and relationships (no using joins)
|
||||
return Cache::remember("all_misc", now()->addMonth(1), function () {
|
||||
return Misc::with(['price'])->get();
|
||||
$query = Misc::with(['price']);
|
||||
if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) {
|
||||
$options = Settings::orderByProcess(Session::get('sort_on'));
|
||||
$query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "misc_services.id"), $options[1]);
|
||||
}
|
||||
return $query->get();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -49,9 +54,6 @@ class Misc extends Model
|
|||
|
||||
public function price()
|
||||
{
|
||||
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]);
|
||||
}
|
||||
return $this->hasOne(Pricing::class, 'service_id', 'id');
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,12 @@ class Reseller extends Model
|
|||
public static function allResellerHosting()
|
||||
{//All reseller hosting and relationships (no using joins)
|
||||
return Cache::remember("all_reseller", now()->addMonth(1), function () {
|
||||
return Reseller::with(['location', 'provider', 'price', 'ips', 'labels'])->get();
|
||||
$query = Reseller::with(['location', 'provider', 'price', 'ips', 'labels']);
|
||||
if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) {
|
||||
$options = Settings::orderByProcess(Session::get('sort_on'));
|
||||
$query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "reseller_hosting.id"), $options[1]);
|
||||
}
|
||||
return $query->get();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -65,9 +70,6 @@ class Reseller extends Model
|
|||
|
||||
public function price()
|
||||
{
|
||||
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]);
|
||||
}
|
||||
return $this->hasOne(Pricing::class, 'service_id', 'id');
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,12 @@ class SeedBoxes extends Model
|
|||
public static function allSeedboxes()
|
||||
{//All seedboxes and relationships (no using joins)
|
||||
return Cache::remember("all_seedboxes", now()->addMonth(1), function () {
|
||||
return SeedBoxes::with(['location', 'provider', 'price'])->get();
|
||||
$query = SeedBoxes::with(['location', 'provider', 'price']);
|
||||
if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) {
|
||||
$options = Settings::orderByProcess(Session::get('sort_on'));
|
||||
$query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "seedboxes.id"), $options[1]);
|
||||
}
|
||||
return $query->get();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -60,9 +65,6 @@ class SeedBoxes extends Model
|
|||
|
||||
public function price()
|
||||
{
|
||||
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]);
|
||||
}
|
||||
return $this->hasOne(Pricing::class, 'service_id', 'id');
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,12 @@ class Server extends Model
|
|||
public static function allServers()
|
||||
{//All servers and relationships (no using joins)
|
||||
return Cache::remember("all_servers", now()->addMonth(1), function () {
|
||||
return Server::with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels'])->get();
|
||||
$query = Server::with(['location', 'provider', 'os', 'price', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels']);
|
||||
if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) {
|
||||
$options = Settings::orderByProcess(Session::get('sort_on'));
|
||||
$query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "servers.id"), $options[1]);
|
||||
}
|
||||
return $query->get();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -58,8 +63,13 @@ class Server extends Model
|
|||
public static function allActiveServers()
|
||||
{//All ACTIVE servers and relationships replaces activeServersDataIndexPage()
|
||||
return Cache::remember("all_active_servers", now()->addMonth(1), function () {
|
||||
return Server::where('active', '=', 1)
|
||||
->with(['location', 'provider', 'os', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'price'])->get();
|
||||
$query = Server::where('active', '=', 1)
|
||||
->with(['location', 'provider', 'os', 'ips', 'yabs', 'yabs.disk_speed', 'yabs.network_speed', 'labels', 'price']);
|
||||
if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) {
|
||||
$options = Settings::orderByProcess(Session::get('sort_on'));
|
||||
$query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "servers.id"), $options[1]);
|
||||
}
|
||||
return $query->get();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -216,9 +226,6 @@ class Server extends Model
|
|||
|
||||
public function price()
|
||||
{
|
||||
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]);
|
||||
}
|
||||
return $this->hasOne(Pricing::class, 'service_id', 'id');
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,12 @@ class Shared extends Model
|
|||
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'])->get();
|
||||
$query = Shared::with(['location', 'provider', 'price', 'ips', 'labels']);
|
||||
if (in_array(Session::get('sort_on'), [3, 4, 5, 6], true)) {
|
||||
$options = Settings::orderByProcess(Session::get('sort_on'));
|
||||
$query->orderBy(Pricing::select("pricings.$options[0]")->whereColumn("pricings.service_id", "shared_hosting.id"), $options[1]);
|
||||
}
|
||||
return $query->get();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -65,9 +70,6 @@ class Shared extends Model
|
|||
|
||||
public function price()
|
||||
{
|
||||
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]);
|
||||
}
|
||||
return $this->hasOne(Pricing::class, 'service_id', 'id');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user