From 8f71b408ef21ebea67a227ff6f615eb18485ce94 Mon Sep 17 00:00:00 2001 From: Alex Ramirez Date: Sun, 12 Nov 2023 22:37:48 -0800 Subject: [PATCH] Null handling of soft deleted tracks for favourites page --- app/Models/Favourite.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Models/Favourite.php b/app/Models/Favourite.php index 0c2500e1..019e05df 100644 --- a/app/Models/Favourite.php +++ b/app/Models/Favourite.php @@ -91,8 +91,11 @@ class Favourite extends Model } else { if ($this->playlist_id) { return $this->playlist; - } // no resource - this should never happen under real circumstances + } else { + // No resource + // In this case, either the resource was + // soft-deleted or something else occurred. return null; } } @@ -101,6 +104,11 @@ class Favourite extends Model public function getTypeAttribute() { - return get_class($this->resource); + // As of PHP 7.2, get_class is picky about null args + if ($resource = $this->resource) { + return get_class($resource); + } else { + return null; + } } }