From 4e3a347e7024e30fc60980fa70074f3eb6c3e3f2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 8 Mar 2023 12:02:36 +0100 Subject: [PATCH] Normalize internal array keys to lowercase Normalize internal array keys to lowercase to make author usernames case-insensitive --- .../src/Framework/Features/Blogging/Models/PostAuthor.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Features/Blogging/Models/PostAuthor.php b/packages/framework/src/Framework/Features/Blogging/Models/PostAuthor.php index ec6b25cad15..a916c54a7a4 100644 --- a/packages/framework/src/Framework/Features/Blogging/Models/PostAuthor.php +++ b/packages/framework/src/Framework/Features/Blogging/Models/PostAuthor.php @@ -8,6 +8,7 @@ use Hyde\Facades\Author; use Hyde\Facades\Config; use Illuminate\Support\Collection; +use function strtolower; use function is_string; /** @@ -65,14 +66,14 @@ public static function getOrCreate(string|array $data): static /** Get an Author from the config, or create it. */ public static function get(string $username): static { - return static::all()->firstWhere('username', $username) ?? Author::create($username); + return static::all()->firstWhere('username', strtolower($username)) ?? Author::create($username); } /** @return \Illuminate\Support\Collection<\Hyde\Framework\Features\Blogging\Models\PostAuthor> */ public static function all(): Collection { return (new Collection(Config::getArray('hyde.authors', [])))->mapWithKeys(function (self $author): array { - return [$author->username => $author]; + return [strtolower($author->username) => $author]; }); }