Comments (10)
This is the way I handle this:
- List all routes in array with
areActiveRoutes(['users.index', 'users.show'])
or - Use
isActiveMatch('users')
which looks for stringusers
in the current URL.
from ekko.
Thanks. I want to avoid (1) as it is cumbersome. Also I wanted to avoid (2) as it is not specific enough on the parts of the URL it matches. I'll see what I can do in a fork, as it looks like the route name matching is just one line in the code that can easily be extended. Maybe a PR if you are happy with the approach.
from ekko.
If you could do a PR that would be great. I haven't had the time lately to add that feature myself so any help is welcome.
from ekko.
I've made a tweak to allow *
as a wildcard character. I'm using for the menu option to administer users in my admin section using a resource controller routing like this: admin.users.*
That way the "administer users" menu item is active no mater whether I'm adding, editing, listing etc. users. Having full wildcards support may be another option, but this kind of forces you to keep the views simpler. If I find it's not sufficient as my app develops, I may well find it necessary to add full RE support, but I'll see how it goes.
Feel free to merge if you like it, or wait until I do a PR after I've run with it for a while :-)
from ekko.
I created a function for this:
public function isActiveRouteMatch($string, $output = "active")
{
if(str_contains(Route::currentRouteName(), $string)) return $output;
return null;
}
<li class="{{ Ekko::isActiveRouteMatch('admin.assinantes') }}"><a href="{{ route('admin.assinantes.index') }}"><i class="fa fa-users"></i> <span>Assinantes</span></a></li>
from ekko.
@diorgesl I lile this one. Could you send a PR for this?
from ekko.
I've updated the docs and extended the wildcard match to multiple route names too (areActiveRoutes()
). I'm using it at the moment for nested resource routes (as shown the docs).
The wildcard is an asterisk (*
) only and matches non-period/full-stop (.
) characters. It is not a full RE match, which could possibly be added as a separate rule. The intend is that no current route matches will be affected, but the wildcard can be easily used where needed without introducing new API methods.
I didn't go for the "contains" match used by the other matching methods, as they are liable to give too many false-positives. For example, I have a "user" resource controller, and also a "foobar.user" nested resource controller. I want to match "user.index", "user.show" etc. for one menu item, without matching "foobar.user.index", "foobar.user.show" etc. which are matched to a separate "foobar" menu item. My change allows me to use "user." and "foobar.user." as separate route name matches that don't overlap.
from ekko.
Thank you. Will be released in version 1.2.0
from ekko.
Thank you :-)
from ekko.
Using 1.2.0 now, and all works wonderfully (after switching my PHP from 5.5 to 5.6).
from ekko.
Related Issues (18)
- BadMethodCallException HOT 5
- Laravel 5.3
- Update documentation
- helpers.php HOT 2
- Wildcard nested route detection not going deep enough HOT 1
- Support URL wildcards HOT 1
- Support route actions HOT 1
- What about compatibility table? HOT 1
- Support for query param strings? HOT 3
- update composer.json for laravel 5.6 HOT 1
- Ekko::areActiveMatch and helper HOT 1
- Laravel 6 released HOT 1
- isActiveAction exist? HOT 2
- how to use it with ARCANEDEV/Localization HOT 2
- Support URLs params ? HOT 1
- Fatal Error HOT 1
- Wildcard on nested routes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ekko.