title: Laravel: Check if slug in a route is equal to slug in database
body: <p>I have an url like <code>/locations/name-of-the-location.ID</code></p>
  
  <p>My route is:</p>
  
  <pre><code>Route::get('locations/{slug}.{location}', ['as' =&gt; 'locations.show', 'uses' =&gt; 'LocationsController@show'])-&gt;where([
      'location' =&gt; '[0-9]+', 
      'slug' =&gt; '[a-z0-9-]+'
  ]);
  </code></pre>
  
  <p>Now I want to check if the slug provided is the same that is saved in the database column 'slug' with my model (because the slug may have changed). If not, then I want to redirect to the correct path.</p>
  
  <p>Where is the best place to do that? I thought of \App\Providers\RouteServiceProvider- but when I try to use <code>Route::currentRouteName()</code> there, I get NULL, maybe because it is 'too early' for that method in the boot() method of RouteServiceProvider.</p>
  
  <p>What I could do, is to work with the path(), but that seems a bit dirty to me, because I work with route prefixes in an other language.</p>
  
  <p>Here's what I tried (I am using a little helper class <code>RouteSlug</code>) - of course it does not work:</p>
  
  <pre><code>public function boot()
  {
      parent::boot();
  
      if (strstr(Route::currentRouteName(), '.', true) == 'locations')
      {
          Route::bind('location', function ($location) {
              $location = \App\Location::withTrashed()-&gt;find($location);
              $parameters = Route::getCurrentRoute()-&gt;parameters();
              $slug = $parameters['slug'];
  
              if ($redirect = \RouteSlug::checkRedirect(Route::getCurrentRoute()-&gt;getName(), $location-&gt;id, $location-&gt;slug, $slug))
              {
                  return redirect($redirect);
              }
              else 
              {
                  return $location;
              }
  
          });
      }
  }
  </code></pre>