Framework: Need an helper

Created on 2 Jan 2018  路  4Comments  路  Source: laravel/framework

  • Laravel Version: 5.5.0
  • PHP Version: 7

Description:

To make a "is-current" vue, i needed to compare the current url and the one we are. Of course, hard writing the comparison like "recipe/index" is not good, so i thought about using a route ... except that routes return a "/recipe/index?" thing so I tried

substr(route("recipe.index", '', FALSE), 1, -1)

which work great but ... it's a bit heavy don't you think ? Is there a way to have a current_uri('recipe.index') thing ? Like when we use a php artisan route list.

Thank you in advance

All 4 comments

Have you checked any of the existing methods on the Route facade? Route::currentRouteName() sounds relevant, and Route::currentRouteNamed(...$patterns) if you need to check for several names.

if (Route::currentRouteNamed('recipe.index')) {
    // Logic goes here.
}

For more stuff, look at https://laravel.com/docs/5.5/routing#accessing-the-current-route

This repo is for bug tracking. Use the forums or slack channel for solving your issue

@Dylan-DPC Not an issue neither a bug, but a proposition of new functionnality, I'm not sure slack or a forum is well qualified to put it there ...

@Epistol then we have laravel/internals repo for future proposals 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sebastianbergmann picture sebastianbergmann  路  93Comments

mianshargeel picture mianshargeel  路  59Comments

thewinterwind picture thewinterwind  路  63Comments

robjbrain picture robjbrain  路  64Comments

GrahamCampbell picture GrahamCampbell  路  139Comments