Tuesday, 14 May 2019

Using regex to make menu item active in laravel adminlte

I'm using Laravel 5.8 with AdminLTE for Laravel.

There's several options to create a menu, one of which is to create it in the provided config file, which I use.

You can specify an active key in the menu that allows you to make the menu have the class that makes the menu item active and activates the dropdown.

I have a menu item, which I would like to make active on these pages:

  • /posts (works with active => ['/posts'])
  • /posts/{post_id} (id are only numbers)

These URL's shouldn't match:

  • /posts/create
  • /posts/anyotherlink
  • /posts/1text

I can not use /posts/* because that would make the create page and some others active.

The readme suggest that you can also use regex to do this. I don't use regex at all, but I came to this, which, according tot regex101 seems to match what I need it to:

^\/posts\/[0-9]+$

I've tried to implement it like so:

[
    'text'    => 'Posts overview',
    'url'     => '/posts',
    'icon'    => 'list',
    'active'  => ['/posts', '^\/posts\/[0-9]+$'],
    'active'  => ['/posts', '/posts/[^0-9]'] // also tried this
],

Unfortunately, this does not seem to work as it doesn't make the menu item active on the pages listed above.

Edit: I've also created an issue in the GitHub repository as I suspect that this might be an issue with the package.

Am I missing something, or doing something wrong?



from Using regex to make menu item active in laravel adminlte

No comments:

Post a Comment