From fca0778c0030c09331b445eaf48eb9ddc685a66c Mon Sep 17 00:00:00 2001 From: Kei Date: Thu, 9 May 2024 01:37:59 +0700 Subject: [PATCH] Improve routeList method --- app/Helpers/Helper.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 346fb279b..be0992311 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -68,6 +68,8 @@ public static function urlDisplay( } /** + * List of potentially colliding routes with shortened link keywords + * * @return array */ public static function routeList(): array @@ -78,8 +80,17 @@ public static function routeList(): array ); return collect($route) - // ex. admin/{any} => admin - ->map(fn ($value) => preg_replace('/(\/){.+/', '', $value)) + // ex. foobar/{route_param?} => foobar + ->map(fn ($value) => preg_replace('/(\/{)([a-zA-Z]+)(\?})$/', '', $value)) + // Remove foo/bar + ->map(fn ($value) => preg_replace('/^([a-zA-Z-_]+)\/([a-zA-Z-\/{}\.]+)/', '', $value)) + // Remove '{route_param}' or '+{route_param}' + ->map(fn ($value) => preg_replace('/^(\+?)({)([a-zA-Z]+)(})/', '', $value)) + // Remove '/' + ->map(fn ($value) => preg_replace('/\//', '', $value)) + // Remove empty value + ->reject(fn ($value) => empty($value)) + ->unique() ->toArray(); } }