diff --git a/src/Contracts/RedirectModelContract.php b/src/Contracts/RedirectModelContract.php index f9de0db..f8fc10e 100644 --- a/src/Contracts/RedirectModelContract.php +++ b/src/Contracts/RedirectModelContract.php @@ -44,5 +44,5 @@ public function syncOldRedirects(self $model, string $finalUrl): void; * @param string $path * @return RedirectModelContract|null */ - public static function findValidOrNull($path): self; + public static function findValidOrNull($path): ?self; } diff --git a/src/Models/Redirect.php b/src/Models/Redirect.php index 3e9817d..b4c1f46 100644 --- a/src/Models/Redirect.php +++ b/src/Models/Redirect.php @@ -25,7 +25,7 @@ class Redirect extends Model implements RedirectModelContract 'old_url', 'new_url', 'status', - ]; + ];\ /** * Boot the model. @@ -129,9 +129,9 @@ public function syncOldRedirects(RedirectModelContract $model, string $finalUrl) * @param string $path * @return Redirect|null */ - public static function findValidOrNull($path): RedirectModelContract + public static function findValidOrNull($path): ?RedirectModelContract { - return static::where('old_url', trim($path, '/')) + return static::where('old_url', $path === '/' ? $path : trim($path, '/')) ->whereNotNull('new_url') ->whereIn('status', array_keys(self::getStatuses())) ->latest()->first();