Coder Social home page Coder Social logo

Support route wildcards? about ekko HOT 10 CLOSED

laravelista avatar laravelista commented on August 23, 2024
Support route wildcards?

from ekko.

Comments (10)

mabasic avatar mabasic commented on August 23, 2024

This is the way I handle this:

  1. List all routes in array with areActiveRoutes(['users.index', 'users.show']) or
  2. Use isActiveMatch('users') which looks for string users in the current URL.

from ekko.

judgej avatar judgej commented on August 23, 2024

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.

mabasic avatar mabasic commented on August 23, 2024

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.

judgej avatar judgej commented on August 23, 2024

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.

diorgesl avatar diorgesl commented on August 23, 2024

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.

mabasic avatar mabasic commented on August 23, 2024

@diorgesl I lile this one. Could you send a PR for this?

from ekko.

judgej avatar judgej commented on August 23, 2024

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.

mabasic avatar mabasic commented on August 23, 2024

Thank you. Will be released in version 1.2.0

from ekko.

judgej avatar judgej commented on August 23, 2024

Thank you :-)

from ekko.

judgej avatar judgej commented on August 23, 2024

Using 1.2.0 now, and all works wonderfully (after switching my PHP from 5.5 to 5.6).

from ekko.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.