Skip to content

Add Route::isFallback() macro? #17

@ivanvermeyen

Description

@ivanvermeyen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions