From d7cb337f5f9d0fa3e5e134370b5050436dbedad6 Mon Sep 17 00:00:00 2001 From: HDVinnie Date: Sat, 8 Jan 2022 03:34:17 -0500 Subject: [PATCH] chore: streamline query builder orderBy calls with asc and desc arguments --- app/Bots/CasinoBot.php | 2 +- app/Bots/NerdBot.php | 2 +- app/Bots/SystemBot.php | 2 +- app/Http/Controllers/API/ChatController.php | 2 +- .../Controllers/API/TorrentController.php | 8 +++--- app/Http/Controllers/BonusController.php | 6 ++--- app/Http/Controllers/ForumController.php | 4 +-- .../MediaHub/CompanyController.php | 4 +-- .../Controllers/MediaHub/GenreController.php | 4 +-- .../MediaHub/NetworkController.php | 2 +- app/Http/Controllers/PlaylistController.php | 2 +- app/Http/Controllers/RssController.php | 2 +- app/Http/Controllers/Staff/RssController.php | 2 +- app/Http/Controllers/UserController.php | 26 +++++++++---------- app/Http/Livewire/CollectionSearch.php | 2 +- app/Http/Livewire/CompanySearch.php | 2 +- app/Http/Livewire/NetworkSearch.php | 2 +- app/Http/Livewire/PersonSearch.php | 2 +- app/Http/Livewire/QuickSearchDropdown.php | 6 ++--- app/Http/Livewire/TorrentCardSearch.php | 4 +-- app/Http/Livewire/TorrentListSearch.php | 4 +-- app/Http/Livewire/TorrentRequestSearch.php | 2 +- app/Models/BonExchange.php | 8 +++--- app/Models/Comment.php | 2 +- app/Models/Ticket.php | 2 +- app/Repositories/ChatRepository.php | 8 +++--- 26 files changed, 56 insertions(+), 56 deletions(-) diff --git a/app/Bots/CasinoBot.php b/app/Bots/CasinoBot.php index b02bedf55..1ed06459e 100644 --- a/app/Bots/CasinoBot.php +++ b/app/Bots/CasinoBot.php @@ -67,7 +67,7 @@ class CasinoBot $output = \str_replace(['{me}', '{command}'], [$this->bot->name, $this->bot->command], $output); if (\str_contains($output, '{bots}')) { $botHelp = ''; - $bots = Bot::where('active', '=', 1)->where('id', '!=', $this->bot->id)->orderBy('position', 'asc')->get(); + $bots = Bot::where('active', '=', 1)->where('id', '!=', $this->bot->id)->orderBy('position')->get(); foreach ($bots as $bot) { $botHelp .= '( ! | / | @)'.$bot->command.' help triggers help file for '.$bot->name."\n"; } diff --git a/app/Bots/NerdBot.php b/app/Bots/NerdBot.php index fd383f280..2f204bbf2 100644 --- a/app/Bots/NerdBot.php +++ b/app/Bots/NerdBot.php @@ -71,7 +71,7 @@ class NerdBot $output = \str_replace(['{me}', '{command}'], [$this->bot->name, $this->bot->command], $output); if (\str_contains($output, '{bots}')) { $botHelp = ''; - $bots = Bot::where('active', '=', 1)->where('id', '!=', $this->bot->id)->orderBy('position', 'asc')->get(); + $bots = Bot::where('active', '=', 1)->where('id', '!=', $this->bot->id)->orderBy('position')->get(); foreach ($bots as $bot) { $botHelp .= '( ! | / | @)'.$bot->command.' help triggers help file for '.$bot->name."\n"; } diff --git a/app/Bots/SystemBot.php b/app/Bots/SystemBot.php index 89b1ac44a..16f237531 100644 --- a/app/Bots/SystemBot.php +++ b/app/Bots/SystemBot.php @@ -62,7 +62,7 @@ class SystemBot $output = \str_replace(['{me}', '{command}'], [$this->bot->name, $this->bot->command], $output); if (\str_contains($output, '{bots}')) { $botHelp = ''; - $bots = Bot::where('active', '=', 1)->where('id', '!=', $this->bot->id)->orderBy('position', 'asc')->get(); + $bots = Bot::where('active', '=', 1)->where('id', '!=', $this->bot->id)->orderBy('position')->get(); foreach ($bots as $bot) { $botHelp .= '( ! | / | @)'.$bot->command.' help triggers help file for '.$bot->name."\n"; } diff --git a/app/Http/Controllers/API/ChatController.php b/app/Http/Controllers/API/ChatController.php index d143cf6ea..f8a70792a 100644 --- a/app/Http/Controllers/API/ChatController.php +++ b/app/Http/Controllers/API/ChatController.php @@ -149,7 +149,7 @@ class ChatController extends Controller $botDirty = 0; $bots = \cache()->get('bots'); if (! $bots || ! \is_array($bots) || \count($bots) < 1) { - $bots = Bot::where('active', '=', 1)->orderBy('position', 'asc')->get(); + $bots = Bot::where('active', '=', 1)->orderBy('position')->get(); $botDirty = 1; } diff --git a/app/Http/Controllers/API/TorrentController.php b/app/Http/Controllers/API/TorrentController.php index 66fbe7140..b41992c44 100644 --- a/app/Http/Controllers/API/TorrentController.php +++ b/app/Http/Controllers/API/TorrentController.php @@ -58,8 +58,8 @@ class TorrentController extends BaseController public function index(): TorrentsResource { return new TorrentsResource(Torrent::with(['category', 'type', 'resolution']) - ->orderBy('sticky', 'desc') - ->orderBy('bumped_at', 'desc') + ->orderByDesc('sticky') + ->orderByDesc('bumped_at') ->paginate(25)); } @@ -334,7 +334,7 @@ class TorrentController extends BaseController }); }) ->when($request->has('uploader'), function ($query) use ($request) { - $match = User::where('username', 'LIKE', '%'.$request->input('uploader').'%')->orderBy('username', 'ASC')->first(); + $match = User::where('username', 'LIKE', '%'.$request->input('uploader').'%')->orderBy('username')->first(); if ($match) { $query->where('user_id', '=', $match->id)->where('anon', '=', 0); } @@ -423,7 +423,7 @@ class TorrentController extends BaseController ->when($request->has('dead'), function ($query) { $query->orWhere('seeders', '=', 0); }) - ->orderBy('sticky', 'desc') + ->orderByDesc('sticky') ->orderBy($request->input('sortField') ?? $this->sortField, $request->input('sortDirection') ?? $this->sortDirection) ->paginate($request->input('perPage') ?? $this->perPage); diff --git a/app/Http/Controllers/BonusController.php b/app/Http/Controllers/BonusController.php index 192429c83..8685ee247 100644 --- a/app/Http/Controllers/BonusController.php +++ b/app/Http/Controllers/BonusController.php @@ -49,7 +49,7 @@ class BonusController extends Controller $userbon = $user->getSeedbonus(); $gifttransactions = BonTransactions::with(['senderObj', 'receiverObj'])->where(function ($query) use ($user) { $query->where('sender', '=', $user->id)->orwhere('receiver', '=', $user->id); - })->where('name', '=', 'gift')->orderBy('date_actioned', 'DESC')->paginate(25); + })->where('name', '=', 'gift')->orderByDesc('date_actioned')->paginate(25); $giftsSent = BonTransactions::where('sender', '=', $user->id)->where('name', '=', 'gift')->sum('cost'); $giftsReceived = BonTransactions::where('receiver', '=', $user->id)->where('name', '=', 'gift')->sum('cost'); @@ -72,7 +72,7 @@ class BonusController extends Controller $userbon = $user->getSeedbonus(); $bontransactions = BonTransactions::with(['senderObj', 'receiverObj'])->where(function ($query) use ($user) { $query->where('sender', '=', $user->id)->orwhere('receiver', '=', $user->id); - })->where('name', '=', 'tip')->orderBy('date_actioned', 'DESC')->paginate(25); + })->where('name', '=', 'tip')->orderByDesc('date_actioned')->paginate(25); $tipsSent = BonTransactions::where('sender', '=', $user->id)->where('name', '=', 'tip')->sum('cost'); $tipsReceived = BonTransactions::where('receiver', '=', $user->id)->where('name', '=', 'tip')->sum('cost'); @@ -95,7 +95,7 @@ class BonusController extends Controller $userbon = $user->getSeedbonus(); $activefl = PersonalFreeleech::where('user_id', '=', $user->id)->first(); $BonExchange = new BonExchange(); - $bontransactions = BonTransactions::with('exchange')->where('sender', '=', $user->id)->where('itemID', '>', 0)->orderBy('date_actioned', 'DESC')->limit(25)->get(); + $bontransactions = BonTransactions::with('exchange')->where('sender', '=', $user->id)->where('itemID', '>', 0)->orderByDesc('date_actioned')->limit(25)->get(); $uploadOptions = $BonExchange->getUploadOptions(); $downloadOptions = $BonExchange->getDownloadOptions(); $personalFreeleech = $BonExchange->getPersonalFreeleechOption(); diff --git a/app/Http/Controllers/ForumController.php b/app/Http/Controllers/ForumController.php index 0b284a951..baec73a11 100644 --- a/app/Http/Controllers/ForumController.php +++ b/app/Http/Controllers/ForumController.php @@ -200,7 +200,7 @@ class ForumController extends Controller $query->whereIn('topics.id', $topicNeos)->orWhereIn('forums.id', $forumNeos); })->groupBy('forums.id'); - $results = $builder->orderBy('topic_created_at', 'desc')->paginate(25); + $results = $builder->orderByDesc('topic_created_at')->paginate(25); $results->setPath('?name='.$request->input('name')); // Total Forums Count @@ -268,7 +268,7 @@ class ForumController extends Controller $pests = []; } - $results = Post::selectRaw('posts.id as id,posts.*')->with(['topic', 'user', 'topic.forum'])->leftJoin('topics', 'posts.topic_id', '=', 'topics.id')->whereNotIn('topics.forum_id', $pests)->orderBy('posts.created_at', 'desc')->paginate(25); + $results = Post::selectRaw('posts.id as id,posts.*')->with(['topic', 'user', 'topic.forum'])->leftJoin('topics', 'posts.topic_id', '=', 'topics.id')->whereNotIn('topics.forum_id', $pests)->orderByDesc('posts.created_at')->paginate(25); // Total Forums Count $numForums = Forum::count(); diff --git a/app/Http/Controllers/MediaHub/CompanyController.php b/app/Http/Controllers/MediaHub/CompanyController.php index f060e5b1c..e62dd270d 100644 --- a/app/Http/Controllers/MediaHub/CompanyController.php +++ b/app/Http/Controllers/MediaHub/CompanyController.php @@ -34,8 +34,8 @@ class CompanyController extends Controller public function show($id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View { $company = Company::withCount('tv', 'movie')->findOrFail($id); - $shows = $company->tv()->orderBy('name', 'asc')->paginate(25); - $movies = $company->movie()->orderBy('title', 'asc')->paginate(25); + $shows = $company->tv()->orderBy('name')->paginate(25); + $movies = $company->movie()->orderBy('title')->paginate(25); return \view('mediahub.company.show', [ 'company' => $company, diff --git a/app/Http/Controllers/MediaHub/GenreController.php b/app/Http/Controllers/MediaHub/GenreController.php index ff731f9b0..f4bc90096 100644 --- a/app/Http/Controllers/MediaHub/GenreController.php +++ b/app/Http/Controllers/MediaHub/GenreController.php @@ -36,8 +36,8 @@ class GenreController extends Controller public function show($id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View { $genre = Genre::withCount(['tv', 'movie'])->findOrFail($id); - $shows = $genre->tv()->orderBy('name', 'asc')->paginate(25); - $movies = $genre->movie()->orderBy('title', 'asc')->paginate(25); + $shows = $genre->tv()->orderBy('name')->paginate(25); + $movies = $genre->movie()->orderBy('title')->paginate(25); return \view('mediahub.genre.show', [ 'genre' => $genre, diff --git a/app/Http/Controllers/MediaHub/NetworkController.php b/app/Http/Controllers/MediaHub/NetworkController.php index 9a0e885fa..15f74c60d 100644 --- a/app/Http/Controllers/MediaHub/NetworkController.php +++ b/app/Http/Controllers/MediaHub/NetworkController.php @@ -34,7 +34,7 @@ class NetworkController extends Controller public function show($id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View { $network = Network::withCount('tv')->findOrFail($id); - $shows = $network->tv()->orderBy('name', 'asc')->paginate(25); + $shows = $network->tv()->orderBy('name')->paginate(25); return \view('mediahub.network.show', [ 'network' => $network, diff --git a/app/Http/Controllers/PlaylistController.php b/app/Http/Controllers/PlaylistController.php index 79ecda6b6..e88cf55e2 100644 --- a/app/Http/Controllers/PlaylistController.php +++ b/app/Http/Controllers/PlaylistController.php @@ -47,7 +47,7 @@ class PlaylistController extends Controller ->orWhere(function ($query) { $query->where('is_private', '=', 1)->where('user_id', '=', \auth()->id()); }); - })->orderBy('name', 'ASC')->paginate(24); + })->orderBy('name')->paginate(24); return \view('playlist.index', ['playlists' => $playlists]); } diff --git a/app/Http/Controllers/RssController.php b/app/Http/Controllers/RssController.php index 6da8fb923..2e5c4e3c4 100644 --- a/app/Http/Controllers/RssController.php +++ b/app/Http/Controllers/RssController.php @@ -36,7 +36,7 @@ class RssController extends Controller { $user = $request->user(); - $publicRss = Rss::where('is_private', '=', 0)->orderBy('position', 'ASC')->get(); + $publicRss = Rss::where('is_private', '=', 0)->orderBy('position')->get(); $privateRss = Rss::where('is_private', '=', 1)->where('user_id', '=', $user->id)->latest()->get(); return \view('rss.index', [ diff --git a/app/Http/Controllers/Staff/RssController.php b/app/Http/Controllers/Staff/RssController.php index 9ba68ff6c..a84932f18 100644 --- a/app/Http/Controllers/Staff/RssController.php +++ b/app/Http/Controllers/Staff/RssController.php @@ -31,7 +31,7 @@ class RssController extends Controller */ public function index($hash = null): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View { - $publicRss = Rss::where('is_private', '=', 0)->orderBy('position', 'ASC')->get(); + $publicRss = Rss::where('is_private', '=', 0)->orderBy('position')->get(); return \view('Staff.rss.index', [ 'hash' => $hash, diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 5df3af483..b1978b7ba 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -147,7 +147,7 @@ class UserController extends Controller public function posts(User $username): \Illuminate\Contracts\View\Factory|\Illuminate\View\View { $user = User::where('username', '=', $username)->firstOrFail(); - $results = Post::selectRaw('posts.id as id,posts.*')->with(['topic', 'user'])->leftJoin('topics', 'posts.topic_id', '=', 'topics.id')->where('posts.user_id', '=', $user->id)->orderBy('posts.created_at', 'desc')->paginate(25); + $results = Post::selectRaw('posts.id as id,posts.*')->with(['topic', 'user'])->leftJoin('topics', 'posts.topic_id', '=', 'topics.id')->where('posts.user_id', '=', $user->id)->orderByDesc('posts.created_at')->paginate(25); return \view('user.posts', [ 'route' => 'forum', @@ -1039,7 +1039,7 @@ class UserController extends Controller \abort_unless($request->user()->id == $user->id, 403); - $groups = Group::where('level', '>', 0)->orderBy('level', 'desc')->get(); + $groups = Group::where('level', '>', 0)->orderByDesc('level')->get(); return \view('user.privacy', ['user' => $user, 'groups'=> $groups]); } @@ -1053,7 +1053,7 @@ class UserController extends Controller \abort_unless($request->user()->id == $user->id, 403); - $groups = Group::where('level', '>', 0)->orderBy('level', 'desc')->get(); + $groups = Group::where('level', '>', 0)->orderByDesc('level')->get(); return \view('user.notification', ['user' => $user, 'groups'=> $groups]); } @@ -1600,13 +1600,13 @@ class UserController extends Controller $query->withAnyStatus(); }])->leftJoin('torrents', 'torrents.info_hash', '=', 'history.info_hash')->where('actual_downloaded', '>', 0) ->whereRaw('history.actual_downloaded > (torrents.size * ('.(\config('hitrun.buffer') / 100).'))') - ->where('history.user_id', '=', $user->id)->groupBy('history.info_hash')->orderBy('completed_at', 'desc') + ->where('history.user_id', '=', $user->id)->groupBy('history.info_hash')->orderByDesc('completed_at') ->paginate(50); } else { $downloads = History::selectRaw('distinct(history.info_hash), max(torrents.id), max(history.completed_at) as completed_at, max(history.created_at) as created_at, max(history.id) as id, max(history.user_id) as user_id, max(history.seedtime) as seedtime, max(history.seeder) as seeder, max(torrents.size) as size,max(torrents.leechers) as leechers,max(torrents.seeders) as seeders,max(torrents.times_completed) as times_completed')->with(['torrent' => function ($query) { $query->withAnyStatus(); }])->leftJoin('torrents', 'torrents.info_hash', '=', 'history.info_hash') - ->where('history.user_id', '=', $user->id)->groupBy('history.info_hash')->orderBy('completed_at', 'desc') + ->where('history.user_id', '=', $user->id)->groupBy('history.info_hash')->orderByDesc('completed_at') ->paginate(50); } @@ -1628,14 +1628,14 @@ class UserController extends Controller }])->selectRaw('distinct(history.info_hash), max(torrents.id), max(history.completed_at) as completed_at, max(history.created_at) as created_at, max(history.id) as id, max(history.user_id) as user_id, max(history.seedtime) as seedtime, max(history.seeder) as seeder, max(torrents.size) as size,max(torrents.leechers) as leechers,max(torrents.seeders) as seeders,max(torrents.times_completed) as times_completed')->leftJoin('torrents', 'torrents.info_hash', '=', 'history.info_hash')->where('actual_downloaded', '>', 0) ->whereRaw('history.actual_downloaded > (torrents.size * ('.(\config('hitrun.buffer') / 100).'))') ->where('history.user_id', '=', $user->id) - ->groupBy('history.info_hash')->orderBy('completed_at', 'desc') + ->groupBy('history.info_hash')->orderByDesc('completed_at') ->paginate(50); } else { $downloads = History::with(['torrent' => function ($query) { $query->withAnyStatus(); }])->selectRaw('distinct(history.info_hash), max(torrents.id), max(history.completed_at) as completed_at, max(history.created_at) as created_at, max(history.id) as id, max(history.user_id) as user_id, max(history.seedtime) as seedtime, max(history.seeder) as seeder, max(torrents.size) as size,max(torrents.leechers) as leechers,max(torrents.seeders) as seeders,max(torrents.times_completed) as times_completed')->leftJoin('torrents', 'torrents.info_hash', '=', 'history.info_hash') ->where('history.user_id', '=', $user->id) - ->groupBy('history.info_hash')->orderBy('completed_at', 'desc') + ->groupBy('history.info_hash')->orderByDesc('completed_at') ->paginate(50); } @@ -1692,7 +1692,7 @@ class UserController extends Controller $query->withAnyStatus(); }])->leftJoin('torrents', 'torrents.info_hash', '=', 'history.info_hash') ->whereRaw('history.actual_downloaded > (torrents.size * ('.(\config('hitrun.buffer') / 100).'))') - ->where('history.user_id', '=', $user->id)->groupBy('history.info_hash')->orderBy('satisfied_at', 'desc') + ->where('history.user_id', '=', $user->id)->groupBy('history.info_hash')->orderByDesc('satisfied_at') ->whereRaw('(history.seedtime < ? and history.immune != 1)', [\config('hitrun.seedtime')]) ->paginate(50); } else { @@ -1700,7 +1700,7 @@ class UserController extends Controller $query->withAnyStatus(); }])->leftJoin('torrents', 'torrents.info_hash', '=', 'history.info_hash') ->whereRaw('history.actual_downloaded > (torrents.size * ('.(\config('hitrun.buffer') / 100).'))') - ->where('history.user_id', '=', $user->id)->groupBy('history.info_hash')->orderBy('satisfied_at', 'desc') + ->where('history.user_id', '=', $user->id)->groupBy('history.info_hash')->orderByDesc('satisfied_at') ->whereRaw('(history.seedtime < ? and history.immune != 1)', [\config('hitrun.seedtime')]) ->paginate(50); } @@ -1731,7 +1731,7 @@ class UserController extends Controller $history = History::with(['torrent' => function ($query) { $query->withAnyStatus(); }])->selectRaw('distinct(history.id),max(history.info_hash) as info_hash,max(history.agent) as agent,max(history.uploaded) as uploaded,max(history.downloaded) as downloaded,max(history.seeder) as seeder,max(history.active) as active,max(history.actual_uploaded) as actual_uploaded,max(history.actual_downloaded) as actual_downloaded,max(history.seedtime) as seedtime,max(history.created_at) as created_at,max(history.updated_at) as updated_at,max(history.completed_at) as completed_at,max(history.immune) as immune,max(history.hitrun) as hitrun,max(history.prewarn) as prewarn,max(torrents.moderated_at) as moderated_at,max(torrents.slug) as slug,max(torrents.user_id) as user_id,max(torrents.name) as name,max(torrents.category_id) as category_id,max(torrents.size) as size,max(torrents.leechers) as leechers,max(torrents.seeders) as seeders,max(torrents.times_completed) as times_completed,max(torrents.status) as status')->leftJoin('torrents', 'torrents.info_hash', '=', 'history.info_hash')->where('history.user_id', '=', $user->id)->groupBy('history.id') - ->orderBy('created_at', 'DESC')->paginate(50); + ->orderByDesc('created_at')->paginate(50); return \view('user.private.torrents', [ 'route' => 'torrents', @@ -1775,7 +1775,7 @@ class UserController extends Controller $logger = 'user.private.uploads'; $uploads = Torrent::with(['tips', 'thanks', 'category'])->selectRaw('distinct(torrents.id),max(torrents.moderated_at) as moderated_at,max(torrents.slug) as slug,max(torrents.user_id) as user_id,max(torrents.name) as name,max(torrents.category_id) as category_id,max(torrents.size) as size,max(torrents.leechers) as leechers,max(torrents.seeders) as seeders,max(torrents.times_completed) as times_completed,max(torrents.created_at) as created_at,max(torrents.status) as status,count(distinct thanks.id) as thanked_total,max(bt.tipped_total) as tipped_total') - ->withAnyStatus()->where('torrents.user_id', '=', $user->id)->leftJoin(DB::raw('(select distinct(bon_transactions.torrent_id),sum(bon_transactions.cost) as tipped_total from bon_transactions group by bon_transactions.torrent_id) as bt'), 'bt.torrent_id', '=', 'torrents.id')->leftJoin('thanks', 'thanks.torrent_id', 'torrents.id')->groupBy('torrents.id')->orderBy('created_at', 'DESC')->paginate(50); + ->withAnyStatus()->where('torrents.user_id', '=', $user->id)->leftJoin(DB::raw('(select distinct(bon_transactions.torrent_id),sum(bon_transactions.cost) as tipped_total from bon_transactions group by bon_transactions.torrent_id) as bt'), 'bt.torrent_id', '=', 'torrents.id')->leftJoin('thanks', 'thanks.torrent_id', 'torrents.id')->groupBy('torrents.id')->orderByDesc('created_at')->paginate(50); return \view($logger, [ 'route' => 'uploads', @@ -1789,7 +1789,7 @@ class UserController extends Controller } $logger = 'user.uploads'; - $uploads = Torrent::selectRaw('distinct(torrents.id),max(torrents.moderated_at) as moderated_at,max(torrents.slug) as slug,max(torrents.user_id) as user_id,max(torrents.name) as name,max(torrents.category_id) as category_id,max(torrents.size) as size,max(torrents.leechers) as leechers,max(torrents.seeders) as seeders,max(torrents.times_completed) as times_completed,max(torrents.created_at) as created_at,max(torrents.status) as status,count(distinct thanks.id) as thanked_total,sum(bon_transactions.cost) as tipped_total')->where('torrents.user_id', '=', $user->id)->where('torrents.status', '=', 1)->where('torrents.anon', '=', 0)->with(['tips', 'thanks'])->leftJoin('bon_transactions', 'bon_transactions.torrent_id', 'torrents.id')->leftJoin('thanks', 'thanks.torrent_id', 'torrents.id')->groupBy('torrents.id')->orderBy('created_at', 'DESC')->paginate(50); + $uploads = Torrent::selectRaw('distinct(torrents.id),max(torrents.moderated_at) as moderated_at,max(torrents.slug) as slug,max(torrents.user_id) as user_id,max(torrents.name) as name,max(torrents.category_id) as category_id,max(torrents.size) as size,max(torrents.leechers) as leechers,max(torrents.seeders) as seeders,max(torrents.times_completed) as times_completed,max(torrents.created_at) as created_at,max(torrents.status) as status,count(distinct thanks.id) as thanked_total,sum(bon_transactions.cost) as tipped_total')->where('torrents.user_id', '=', $user->id)->where('torrents.status', '=', 1)->where('torrents.anon', '=', 0)->with(['tips', 'thanks'])->leftJoin('bon_transactions', 'bon_transactions.torrent_id', 'torrents.id')->leftJoin('thanks', 'thanks.torrent_id', 'torrents.id')->groupBy('torrents.id')->orderByDesc('created_at')->paginate(50); return \view($logger, [ 'route' => 'uploads', @@ -1846,7 +1846,7 @@ class UserController extends Controller $seeds = Peer::with(['torrent' => function ($query) { $query->withAnyStatus(); }])->selectRaw('distinct(torrents.info_hash),max(peers.id) as id,max(torrents.name) as name,max(torrents.seeders) as seeders,max(torrents.leechers) as leechers,max(torrents.times_completed) as times_completed,max(torrents.size) as size,max(history.info_hash) as history_info_hash,max(history.created_at) as history_created_at,max(torrents.id) as torrent_id,max(history.seedtime) as seedtime')->leftJoin('torrents', 'torrents.id', '=', 'peers.torrent_id')->leftJoin('history', 'history.info_hash', '=', 'torrents.info_hash')->where('peers.user_id', '=', $user->id)->whereRaw('history.user_id = ? and history.seeder = ?', [$user->id, 1]) - ->where('peers.seeder', '=', 1)->orderBy('history_created_at', 'DESC')->groupBy('torrents.info_hash') + ->where('peers.seeder', '=', 1)->orderByDesc('history_created_at')->groupBy('torrents.info_hash') ->paginate(50); return \view('user.private.seeds', ['user' => $user, diff --git a/app/Http/Livewire/CollectionSearch.php b/app/Http/Livewire/CollectionSearch.php index 32aae0b05..e52191b77 100644 --- a/app/Http/Livewire/CollectionSearch.php +++ b/app/Http/Livewire/CollectionSearch.php @@ -43,7 +43,7 @@ class CollectionSearch extends Component return Collection::withCount('movie') ->with('movie') ->where('name', 'LIKE', '%'.$this->search.'%') - ->orderBy('name', 'asc') + ->orderBy('name') ->paginate(25); } diff --git a/app/Http/Livewire/CompanySearch.php b/app/Http/Livewire/CompanySearch.php index 75a01b642..9ad93b49e 100644 --- a/app/Http/Livewire/CompanySearch.php +++ b/app/Http/Livewire/CompanySearch.php @@ -42,7 +42,7 @@ class CompanySearch extends Component { return Company::withCount('tv', 'movie') ->where('name', 'LIKE', '%'.$this->search.'%') - ->orderBy('name', 'asc') + ->orderBy('name') ->paginate(30); } diff --git a/app/Http/Livewire/NetworkSearch.php b/app/Http/Livewire/NetworkSearch.php index 72d2ed1c7..dd70342ea 100644 --- a/app/Http/Livewire/NetworkSearch.php +++ b/app/Http/Livewire/NetworkSearch.php @@ -42,7 +42,7 @@ class NetworkSearch extends Component { return Network::withCount('tv') ->where('name', 'LIKE', '%'.$this->search.'%') - ->orderBy('name', 'asc') + ->orderBy('name') ->paginate(30); } diff --git a/app/Http/Livewire/PersonSearch.php b/app/Http/Livewire/PersonSearch.php index 22da0c488..86dde0f6b 100644 --- a/app/Http/Livewire/PersonSearch.php +++ b/app/Http/Livewire/PersonSearch.php @@ -42,7 +42,7 @@ class PersonSearch extends Component { return Person::select(['id', 'still', 'name']) ->whereNotNull('still')->where('name', 'LIKE', '%'.$this->search.'%') - ->orderBy('name', 'asc') + ->orderBy('name') ->paginate(30); } diff --git a/app/Http/Livewire/QuickSearchDropdown.php b/app/Http/Livewire/QuickSearchDropdown.php index cfaa9d7c5..3f56b62d2 100644 --- a/app/Http/Livewire/QuickSearchDropdown.php +++ b/app/Http/Livewire/QuickSearchDropdown.php @@ -23,7 +23,7 @@ class QuickSearchDropdown extends Component $search_results = Movie::query() ->select(['id', 'poster', 'title', 'release_date']) ->where('title', 'LIKE', '%'.$this->movie.'%') - ->orderBy('title', 'asc') + ->orderBy('title') ->take(10) ->get(); } @@ -32,7 +32,7 @@ class QuickSearchDropdown extends Component $search_results = Tv::query() ->select(['id', 'poster', 'name', 'first_air_date']) ->where('name', 'LIKE', '%'.$this->series.'%') - ->orderBy('name', 'asc') + ->orderBy('name') ->take(10) ->get(); } @@ -42,7 +42,7 @@ class QuickSearchDropdown extends Component ->select(['id', 'still', 'name']) ->whereNotNull('still') ->where('name', 'LIKE', '%'.$this->person.'%') - ->orderBy('name', 'asc') + ->orderBy('name') ->take(10) ->get(); } diff --git a/app/Http/Livewire/TorrentCardSearch.php b/app/Http/Livewire/TorrentCardSearch.php index f8ce0af1e..47f77bd05 100644 --- a/app/Http/Livewire/TorrentCardSearch.php +++ b/app/Http/Livewire/TorrentCardSearch.php @@ -218,7 +218,7 @@ class TorrentCardSearch extends Component $query->where('mediainfo', 'LIKE', '%'.$this->mediainfo.'%'); }) ->when($this->uploader, function ($query) { - $match = User::where('username', 'LIKE', '%'.$this->uploader.'%')->orderBy('username', 'ASC')->first(); + $match = User::where('username', 'LIKE', '%'.$this->uploader.'%')->orderBy('username')->first(); if ($match) { $query->where('user_id', '=', $match->id)->where('anon', '=', 0); } @@ -361,7 +361,7 @@ class TorrentCardSearch extends Component $q->where('user_id', '=', \auth()->user()->id)->where('active', '=', false)->where('seeder', '=', false)->where('seedtime', '=', '0'); }); }) - ->orderBy('sticky', 'desc') + ->orderByDesc('sticky') ->orderBy($this->sortField, $this->sortDirection) ->paginate($this->perPage); } diff --git a/app/Http/Livewire/TorrentListSearch.php b/app/Http/Livewire/TorrentListSearch.php index 1d4a3f987..33b04c7a6 100644 --- a/app/Http/Livewire/TorrentListSearch.php +++ b/app/Http/Livewire/TorrentListSearch.php @@ -218,7 +218,7 @@ class TorrentListSearch extends Component $query->where('mediainfo', 'LIKE', '%'.$this->mediainfo.'%'); }) ->when($this->uploader, function ($query) { - $match = User::where('username', 'LIKE', '%'.$this->uploader.'%')->orderBy('username', 'ASC')->first(); + $match = User::where('username', 'LIKE', '%'.$this->uploader.'%')->orderBy('username')->first(); if ($match) { $query->where('user_id', '=', $match->id)->where('anon', '=', 0); } @@ -361,7 +361,7 @@ class TorrentListSearch extends Component $q->where('user_id', '=', \auth()->user()->id)->where('active', '=', false)->where('seeder', '=', false)->where('seedtime', '=', '0'); }); }) - ->orderBy('sticky', 'desc') + ->orderByDesc('sticky') ->orderBy($this->sortField, $this->sortDirection) ->paginate($this->perPage); } diff --git a/app/Http/Livewire/TorrentRequestSearch.php b/app/Http/Livewire/TorrentRequestSearch.php index 429c6cbf8..f4d9a3182 100644 --- a/app/Http/Livewire/TorrentRequestSearch.php +++ b/app/Http/Livewire/TorrentRequestSearch.php @@ -134,7 +134,7 @@ class TorrentRequestSearch extends Component $query->where('name', 'LIKE', '%'.$this->name.'%'); }) ->when($this->requestor, function ($query) { - $match = User::where('username', 'LIKE', '%'.$this->requestor.'%')->orderBy('username', 'ASC')->first(); + $match = User::where('username', 'LIKE', '%'.$this->requestor.'%')->orderBy('username')->first(); if ($match) { $query->where('user_id', '=', $match->id)->where('anon', '=', 0); } diff --git a/app/Models/BonExchange.php b/app/Models/BonExchange.php index 49208119b..5a302d9e3 100644 --- a/app/Models/BonExchange.php +++ b/app/Models/BonExchange.php @@ -79,7 +79,7 @@ class BonExchange extends Model public function getDownloadOptions(): array { return self::where('download', '=', true) - ->orderBy('value', 'asc') + ->orderBy('value') ->get(); } @@ -89,7 +89,7 @@ class BonExchange extends Model public function getUploadOptions(): array { return self::where('upload', '=', true) - ->orderBy('value', 'asc') + ->orderBy('value') ->get(); } @@ -99,7 +99,7 @@ class BonExchange extends Model public function getPersonalFreeleechOption(): array { return self::where('personal_freeleech', '=', true) - ->orderBy('value', 'asc') + ->orderBy('value') ->get(); } @@ -109,7 +109,7 @@ class BonExchange extends Model public function getInviteOption(): array { return self::where('invite', '=', true) - ->orderBy('value', 'asc') + ->orderBy('value') ->get(); } diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 7f8007b58..ca96de0e9 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -138,7 +138,7 @@ class Comment extends Model public static function checkForStale(Ticket $ticket): void { if (empty($ticket->reminded_at) || \strtotime($ticket->reminded_at) < \strtotime('+ 3 days')) { - $last_comment = $ticket->comments()->orderBy('id', 'desc')->first(); + $last_comment = $ticket->comments()->orderByDesc('id')->first(); if (\property_exists($last_comment, 'id') && $last_comment->id !== null && ! $last_comment->user->is_modo && \strtotime($last_comment->created_at) < \strtotime('- 3 days')) { \event(new TicketWentStale($last_comment->ticket)); diff --git a/app/Models/Ticket.php b/app/Models/Ticket.php index 3630eb85e..33c7c7a3a 100644 --- a/app/Models/Ticket.php +++ b/app/Models/Ticket.php @@ -30,7 +30,7 @@ class Ticket extends Model public function scopeStale($query) { return $query->with(['comments' => function ($query) { - $query->orderBy('id', 'desc'); + $query->orderByDesc('id'); }, 'comments.user']) ->has('comments') ->where('reminded_at', '<', \strtotime('+ 3 days')) diff --git a/app/Repositories/ChatRepository.php b/app/Repositories/ChatRepository.php index 26c96cc47..582b417be 100644 --- a/app/Repositories/ChatRepository.php +++ b/app/Repositories/ChatRepository.php @@ -56,7 +56,7 @@ class ChatRepository ])->where(function ($query) use ($userId) { $query->where('user_id', '=', $userId); }) - ->orderBy('id', 'asc') + ->orderBy('id') ->get(); } @@ -207,7 +207,7 @@ class ChatRepository ])->where(function ($query) use ($roomId) { $query->where('chatroom_id', '=', $roomId); }) - ->orderBy('id', 'desc') + ->orderByDesc('id') ->limit(\config('chat.message_limit')) ->get(); } @@ -226,7 +226,7 @@ class ChatRepository ])->where(function ($query) use ($senderId, $systemUserId) { $query->whereRaw('(user_id = ? and receiver_id = ?)', [$senderId, $systemUserId])->orWhereRaw('(user_id = ? and receiver_id = ?)', [$systemUserId, $senderId]); })->where('bot_id', '=', $botId) - ->orderBy('id', 'desc') + ->orderByDesc('id') ->limit(\config('chat.message_limit')) ->get(); } @@ -243,7 +243,7 @@ class ChatRepository ])->where(function ($query) use ($senderId, $targetId) { $query->whereRaw('(user_id = ? and receiver_id = ?)', [$senderId, $targetId])->orWhereRaw('(user_id = ? and receiver_id = ?)', [$targetId, $senderId]); }) - ->orderBy('id', 'desc') + ->orderByDesc('id') ->limit(\config('chat.message_limit')) ->get(); }