Ad

How Get Laravel Route Alias?

I have next code

Route::group(['as' => 'admin.search.'], function () {
    Route::get('admin/query', ['uses' => 'Admin\[email protected]', 'as' => 'query']);
    Route::get('admin/search', ['uses' => 'Admin\[email protected]', 'as' => 'index');
    Route::post('admin/search', ['uses' =>'Admin\[email protected]', 'as' => 'full');
});

And i check route in layout

@if (!Route::is('admin.search.index') || !Route::is('admin.search.full'))
      @include('partials.forms.global_search')
@endif

But is not work. How i can know route which now i am ?

Ad

Answer

You could use this function, it returns you route name in your case it will be admin.search.query etc...

Route::getCurrentRoute()->getName()

And check it's !Route::is('admin.search.full') doesn't make sense because it's a post route handler.

In your case code will be

@if (Route::getCurrentRoute()->getName() === 'admin.search.search')
      @include('partials.forms.global_search')
@endif
Ad
source: stackoverflow.com
Ad