-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
...to easily check if a route name exists without worrying about prepending the locale. It will either accept a locale as the second argument, or use the current identified locale.
- Loading branch information
1 parent
33bfafa
commit 263311f
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace CodeZero\LocalizedRoutes\Macros; | ||
|
||
use Illuminate\Support\Facades\App; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
class LocalizedHasMacro | ||
{ | ||
/** | ||
* Register the macro. | ||
* | ||
* @return void | ||
*/ | ||
public static function register() | ||
{ | ||
Route::macro('localizedHas', function ($name, $locale = null) { | ||
$locale = $locale ?? App::getLocale(); | ||
if (! $this->routes->hasNamedRoute($locale . ".{$name}")) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
} | ||
} |