diff options
| author | Developer | 2026-06-27 04:05:43 +0200 |
|---|---|---|
| committer | Developer | 2026-06-27 04:05:43 +0200 |
| commit | 33b69f87babac5116db923b906512411488eb28a (patch) | |
| tree | a810eac806de16a68e7e6ec81fa13d3d755fb7de | |
| parent | aa9efa6cb7d60a6e501088fae3aecb08aee3246e (diff) | |
| download | curious-33b69f87babac5116db923b906512411488eb28a.tar.gz | |
feat: add ascending/descending sort direction toggle to cinema
Active sort button toggles direction on click, showing ▲ for asc and ▼ for desc.
Default direction is desc for all sort options.
| -rw-r--r-- | app/Http/Controllers/CinemaController.php | 9 | ||||
| -rw-r--r-- | resources/views/cinema.blade.php | 8 |
2 files changed, 13 insertions, 4 deletions
diff --git a/app/Http/Controllers/CinemaController.php b/app/Http/Controllers/CinemaController.php index d79d037..8a9bb0e 100644 --- a/app/Http/Controllers/CinemaController.php +++ b/app/Http/Controllers/CinemaController.php @@ -10,10 +10,15 @@ class CinemaController extends Controller public function cinema(Request $request) { $order = $request->input('order', 'ref_count'); + $direction = $request->input('direction', 'desc'); $validOrders = ['ref_count', 'score', 'num_votes', 'num_accolades', 'start_year']; + $validDirections = ['asc', 'desc']; if (! in_array($order, $validOrders)) { $order = 'ref_count'; } + if (! in_array($direction, $validDirections)) { + $direction = 'desc'; + } $refCounts = DB::connection('cinema') ->table('links') @@ -47,7 +52,7 @@ class CinemaController extends Controller ->whereNotNull('imdb.primary_title') ->whereNotNull('imdb.wiki_article') ->where('imdb.title_type', 'movie') - ->orderBy($order, 'desc') + ->orderBy($order, $direction) ->simplePaginate(12); $total = DB::connection('cinema') @@ -57,7 +62,7 @@ class CinemaController extends Controller ->where('title_type', 'movie') ->count(); - return view('cinema', ['movies' => $movies, 'count' => $total, 'order' => $order]); + return view('cinema', ['movies' => $movies, 'count' => $total, 'order' => $order, 'direction' => $direction]); } public function show($id) diff --git a/resources/views/cinema.blade.php b/resources/views/cinema.blade.php index ea2bdeb..eb6b085 100644 --- a/resources/views/cinema.blade.php +++ b/resources/views/cinema.blade.php @@ -124,9 +124,13 @@ html { ['start_year', 'Release Date'], ] as [$key, $label]) @if ( (isset($order) ? $order : 'ref_count') == $key ) - <a class="btn btn-sm btn-primary my-1" href="{{ url()->current() }}?order={{ $key }}">{{ $label }}</a> + @if ( (isset($direction) ? $direction : 'desc') == 'desc' ) + <a class="btn btn-sm btn-primary my-1" href="{{ url()->current() }}?order={{ $key }}&direction=asc">{{ $label }} ▲</a> + @else + <a class="btn btn-sm btn-primary my-1" href="{{ url()->current() }}?order={{ $key }}&direction=desc">{{ $label }} ▼</a> + @endif @else - <a class="btn btn-sm btn-outline-secondary my-1" href="{{ url()->current() }}?order={{ $key }}">{{ $label }}</a> + <a class="btn btn-sm btn-outline-secondary my-1" href="{{ url()->current() }}?order={{ $key }}&direction=desc">{{ $label }}</a> @endif @endforeach </div> |
