1 | <?php |
||
2 | |||
3 | use Illuminate\Support\Facades\URL; |
||
4 | use Illuminate\Support\Facades\Route; |
||
5 | |||
6 | if (! function_exists('isActive')) { |
||
7 | /** |
||
8 | * Set the active class to the current opened menu. |
||
9 | * |
||
10 | * @param array|string $route |
||
11 | * @param string $className |
||
12 | * @return string |
||
13 | */ |
||
14 | function isActive($route, $className = 'active'): string |
||
15 | { |
||
16 | if (is_array($route)) { |
||
17 | return in_array(Route::currentRouteName(), $route) ? $className : ''; |
||
18 | } |
||
19 | if (Route::currentRouteName() == $route) { |
||
20 | return $className; |
||
21 | } |
||
22 | if (strpos(URL::current(), $route)) { |
||
23 | return $className; |
||
24 | } |
||
0 ignored issues
–
show
|
|||
25 | } |
||
26 | } |
||
27 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: