Skip to content

[5.4] Adds isRouteName method - #19202

Merged
taylorotwell merged 3 commits into
laravel:5.4from
mlantz:5.4
May 15, 2017
Merged

[5.4] Adds isRouteName method#19202
taylorotwell merged 3 commits into
laravel:5.4from
mlantz:5.4

Conversation

@mlantz

@mlantz mlantz commented May 15, 2017

Copy link
Copy Markdown
Contributor

Adds a isRouteName method to the Request.

For use cases such as Request::isRouteName(‘foo.bar’) this allows easier route changes in the future.

@mlantz mlantz changed the title Adds isRouteName method [5.4] Adds isRouteName method May 15, 2017
Comment thread src/Illuminate/Http/Request.php Outdated
if ($this->route()->getName() == $name) {
return true;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be reduced to just return $this->route()->getName() === $name;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call

@decadence decadence May 15, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better: $this->route()->currentRouteNamed($name)

P.S. I'm wrong, this method only for Route facade.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's worth to add method isName for Route instances.

@taylorotwell
taylorotwell merged commit 2a42036 into laravel:5.4 May 15, 2017
@decadence decadence mentioned this pull request May 16, 2017
@ruchernchong

ruchernchong commented May 30, 2017

Copy link
Copy Markdown

Can this be used as request()->isRouteName()?

@decadence

decadence commented May 30, 2017

Copy link
Copy Markdown
Contributor

Yes, but original method was renamed to routeIs AFAIK

@mlantz

mlantz commented May 30, 2017

Copy link
Copy Markdown
Contributor Author

I tried isRouteName but it looks like it got switched :) still super handy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants