letrunghieu / active

The helper class for Laravel applications to get active class base on current route
https://www.hieule.info/tag/laravel-active/
MIT License
414 stars 83 forks source link

Feature: exclude possible routes from pattern #25

Closed lowerends closed 7 years ago

lowerends commented 8 years ago

I'm encountering a use case where I need a pattern to match except for a specific URL. For example, I want the pattern 'users*' to match except for 'users/all'. If I'm not mistaken, this is not possible yet with this package, so I'm looking for feedback whether it would be useful to add this.

Thanks!

antick commented 8 years ago

I support this. This is useful so we don't have to write all the routes there to tell the active class to be activated. For example I want to put an active class for user module but I have add, edit, view and other pages there as well so for every action I'll have to make a condition. This makes it ugly and messy.

Right now as an alternate I do this which solves the problem and I don't have to add condition for all my pages like add, edit, view. They all exist in a same controller so passing the name itself will get it going.

{{ active_class(current_controller() == controller('Dashboard'), 'active', '') }}

//my helper.php

function controller($name)
{
    return 'App\\Http\\Controllers\\'.$name.'Controller';
}