laravel-localized-routes icon indicating copy to clipboard operation
laravel-localized-routes copied to clipboard

Add Route::isFallback() macro?

Open ivanvermeyen opened this issue 5 years ago • 0 comments

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.

ivanvermeyen avatar Jan 13 '20 16:01 ivanvermeyen