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

pattern not working #2

Closed dragonfire1119 closed 10 years ago

dragonfire1119 commented 10 years ago

Thanks for the script.

Problem

when I'm on /dragonfire1119 route and try Active::pattern(Auth::user()->username); it doesn't return active.

Example of a working solution

Request::is(Auth::user()->username) ? 'active' : '' This works just fine.

letrunghieu commented 10 years ago

Sorry for the late respond, I have a hard week in my current project.

This is an expected behavior. The pattern method wild check the pattern with the current route URI from the start of the string. So /dragonfire1119 will not be matched by dragonfire1119 but *dragonfire1119 instead.

However, how can we get the /dragonfire1119 URI? I have try and only get /dragonfire1119 as URI when navigating to my-laravel.com/dragonfire1119 :(

dragonfire1119 commented 10 years ago

Thanks for the response & it's fine everybody has to work.

Laravel has a helpful facade to get the URI

Request::path()

It returns dragonfire1119 if you want to get a slash on the start of the string that's easy.

$uri = '/' . Request::path();

I think that's what your asking?

letrunghieu commented 10 years ago

May I know when did you call the Active::pattern method? I tried to go to localhost/dragonfire1119 and the result of Active::pattern('dragonfire1119') is stil correct (which is active string as expected).

dragonfire1119 commented 10 years ago

@letrunghieu I called it on the html of the twitter bootstrap menu.

<li class="{{ Active::pattern(Auth::user()->username) }}"><a href="#">Link</a></li>
letrunghieu commented 10 years ago

After setting up a demo project and simulating your actions. I've detect the incorrect code and fixed it. You can run composer update now to get the 1.2.1 version. The demo project can be found at this repo Thank you for help me improve this package :smile_cat:

dragonfire1119 commented 10 years ago

@letrunghieu Your welcome glad I could help.