Skip to content

Commit

Permalink
allow for nullable result on find redirect method
Browse files Browse the repository at this point in the history
  • Loading branch information
zbiller committed Jun 3, 2019
1 parent 8517c41 commit 3256f86
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Contracts/RedirectModelContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions src/Models/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Redirect extends Model implements RedirectModelContract
'old_url',
'new_url',
'status',
];
];\
/**
* Boot the model.
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3256f86

Please sign in to comment.