Forum

laravel - check cur...
 
Notifications
Clear all

laravel - check current controller name or current location for sidebar highlight

1 Posty
1 Users
0 Reactions
632 Widok
0
Topic starter

how to detect currently selected controller? (blade template)

1 Answer
0
Topic starter
  1. Create helper
    1. app/helpers.app
    2. register it inside composer.json
          "autoload": {
              "psr-4": {
                  "App\\": "app/",
                  "Database\\Factories\\": "database/factories/",
                  "Database\\Seeders\\": "database/seeders/"
              },
              "files": [
                  "app/helpers.php"
              ]
          },
  2. Inside helpers.php
    function isMenuItemSelected($url)
    {
    
        if (url()->current() == $url)
            return 'active';
        return;
    }
  3. how to detect currently active menu item

          <a
                    href="{{route('forms.index')}}"
                    class="list-group-item list-group-item-action py-2 ripple {{isMenuItemSelected(route('forms.index'))}}"
                >

Odpowiedź

Author Name

Author Email

Your question *

 
Preview 0 Revisions Saved
Share: