Check route with variable on Laravel 5.1

Asked

Viewed 363 times

2

I am using the code below to assign the class "active" when on the route "product" or "product/create".

<li {!! Request::is('produto', 'produto/create')? 'class="active"' : null !!}>

Now I need to do the same when editing the product, and the editing route has a variable that is the product id, how do I solve this?

Example of routes:

produto/1/edit
produto/7/edit

1 answer

2


The method Request::is accepted wildcards (*) according to the documentation.

The is method Allows you to Verify that the incoming request URI Matches a Given Pattern. You may use the * Character as a wildcard when Utilizing this method:

if ($request->is('admin/*')) {
    //
}

In your case, try the following

<li {!! Request::is('produto/*/edit')? 'class="active"' : null !!}>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.