consil

I've seen this package used by a few demos, and and trying it out myself:

https://github.com/laravelista/Ekko

So far, it's working well, but it needs a wildcard or pattern match for the route name, for which I'm working on a PR.

Edit: Ekko now supports wildcard path names and multiple path names. This is absolutely essential for my use-case as some parts of my admin structure are four levels deep (since it models some real-life structures that need to be set up). This allows multiple sub-menus to activate the top-level menu that they are under. The wildcards then support resource-based URLs.

This is my top-level side-menu option for a "show", which lights up when any of about 30 pages under it are being used:

<li class="{{ Ekko::areActiveRoutes(['admin.shows.*', 'admin.shows.groups.*', 'admin.shows.groups.judges.*', 'admin.shows.products.*', 'admin.shows.orders.*']) }}">
    <a href="{{ route('admin.shows.index') }}">Shows</a>
</li>

My aims in choosing this were:

  • Not to reinvent this common requirement yet again. Yes, the 80% use-case might be quick and simple, but you will quickly hit limitations once your application becomes a little more complex.
  • Choose an open source package that gets most of the way and offer PRs to improve it to better fit my use-case (for both me and others in future projects).
  • To minimise PHP in the HTML markup - conditions, ternary operator etc. Just calling a function was the most I wanted to put into the markup.
  • To match against route names rather than paths. The path stays in routes.php in my applications and ALL other parts of the application just refer to route names. That way paths can be moved and juggled around as the application and its needs grow, without the need to find every instance that references a path.

On that last point, Ekko does support path matches too, so it's there if you want to use it.

Return to Thread...