This is the second post on a Laravel Report series that I'm starting. For part 1, check out https://blog.deleu.dev/laravel-report-dynamic-page-size/.
The user may choose to sort by Staff Member responsible for tickets or maybe for creation date (oldest to newest).
public function register() { $this->registerPage(); $this->registerSort(); } public function registerPage(): void { $this->app->bind(Page::class, function () { $request = $this->app->make(Request::class); return new Page((int) $request->input('per_page', Page::DEFAULT)); }); } public function registerSort(): void { $this->app->bind(Sort::class, function () { $request = $this->app->make(Request::class); $field = $request->input('sort.field'); $direction = $request->input('sort.direction'); return new Sort($field, $direction); }); }
in_array($this->field, $this->available)) { abort(422, "Sorting on [$this->field] is not possible."); } return true; } public function fallback(string $field, string $direction): self { if (!