Skip to content

Commit

Permalink
handling param is enum type
Browse files Browse the repository at this point in the history
  • Loading branch information
yusronarif committed Oct 14, 2022
1 parent 7d126f3 commit 58d76b2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private function activeRoute(string $route = '', array $params = []): bool
}

try {
if (request()->routeIs("{$route}*")) {
if (request()->routeIs($route, "{$route}.*")) {
if (empty($params)) {
return true;
}
Expand All @@ -54,15 +54,28 @@ private function activeRoute(string $route = '', array $params = []): bool
if (is_int($key)) {
$key = $paramNames[$key];
}

if (
$requestRoute->parameter($key) instanceof \Illuminate\Database\Eloquent\Model
&& $value instanceof \Illuminate\Database\Eloquent\Model
&& $requestRoute->parameter($key)->id != $value->id
) {
return false;
}
if ($requestRoute->parameter($key) != $value) {
return false;

if (is_object($requestRoute->parameter($key))) {
// try to check param is enum type
try {
if ($requestRoute->parameter($key)->value && $requestRoute->parameter($key)->value != $value) {
return false;
}
} catch (Exception $e) {
return false;
}
} else {
if ($requestRoute->parameter($key) != $value) {
return false;
}
}
}

Expand Down

0 comments on commit 58d76b2

Please sign in to comment.