0

Is there a way to check the current page's route name with blade? I have a blade layout template that needs to change it's <body> attribute by the current uri. Note that I need to do this through blade, not js.

Here is an example snippet that illustrates what I want to do:

@if (URL::current() == {{ route('admin.index') }}) //not valid syntax
    <body class="dashboard" id="top">
@else 
    <body class="not-dashboard" id="not-top">
@endif
Silver Flash
  • 871
  • 3
  • 7
  • 16
  • Does this answer your question? [How to Get the Current URL Inside @if Statement (Blade) in Laravel 4?](https://stackoverflow.com/questions/17591181/how-to-get-the-current-url-inside-if-statement-blade-in-laravel-4) – Robby Alvian Jaya Mulia Nov 16 '20 at 04:37

1 Answers1

5

you can try routeIs() helper

@if (request()->routeIs('admin.index'))
<body class="dashboard" id="top">
@else
<body class="not-dashboard" id="not-top">
@endif

and you code have syntax error which fix is

@if (URL::current() == route('admin.index')) // remove those curly braces  
    <body class="dashboard" id="top">
@else 
    <body class="not-dashboard" id="not-top">
@endif
Kamlesh Paul
  • 11,778
  • 2
  • 20
  • 33