From ef92cc647d73744234a8b8d8857bd1d992d1a0a1 Mon Sep 17 00:00:00 2001 From: Benjamin Takats Date: Wed, 18 Jan 2023 16:50:46 +0100 Subject: [PATCH] orderBy --- app/Nova/Episode.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/Nova/Episode.php b/app/Nova/Episode.php index 9f9a444e..c2cd50cd 100644 --- a/app/Nova/Episode.php +++ b/app/Nova/Episode.php @@ -27,6 +27,7 @@ class Episode extends Resource public static $search = [ 'id', ]; + public static $orderBy = ['data->datePublished' => 'desc']; public static function afterUpdate(NovaRequest $request, Model $model) { @@ -62,11 +63,6 @@ class Episode extends Resource } } - public function title() - { - return $this->data['title']; - } - public static function afterCreate(NovaRequest $request, Model $model) { \App\Models\User::find(1) @@ -76,6 +72,20 @@ class Episode extends Resource ->toString())); } + protected static function applyOrderings($query, array $orderings) + { + if (empty($orderings) && property_exists(static::class, 'orderBy')) { + $orderings = static::$orderBy; + } + + return parent::applyOrderings($query, $orderings); + } + + public function title() + { + return $this->data['title']; + } + public function subtitle() { return __('Created by: :name', ['name' => $this->createdBy->name]);