laravel-localized-routes
laravel-localized-routes copied to clipboard
Add Route::isFallback() macro?
It would be convenient to have a short Route::isFallback() method, for example when generating a locale switcher like this:
@foreach(config('localized-routes.supported-locales') as $locale)
@if ((Route::isLocalized() || Route::isFallback()) && ! App::isLocale($locale))
<a href="{{ Route::localizedUrl($locale) }}">{{ strtoupper($locale) }}</a>
@endif
@endforeach
Right now, Laravel doesn't have this method, so I added a macro to the boot() method of the RouteServiceProvider of my project:
Route::macro('isFallback', function () {
return Route::current() && Route::current()->isFallback;
});
I'm not sure if this is something I should add to this package or not, just for convenience... For now, I'm just leaving it here for reference.