Vladimir Szabo
Vladimir Szabo

Reputation: 458

Laravel Routing - dashes

I need to make a route that has dashes after variables. What I want is easily explained by code (this is what I tried and it`s not working)

Route::any('tournament/{sportName}/{regionName}/{tournamentName}-odds', array('as' => 'tournament-page', 'uses' => 'HomeController@tournament'));

The the problem is this part "-odds". When I add that I get a Laravel error of this content

$others = $this->checkForAlternateVerbs($request);

        if (count($others) > 0)
        {
            return $this->getOtherMethodsRoute($request, $others);
        }

        throw new NotFoundHttpException;

How can I do this (add dashes after parameters in routes)? Thanks

Upvotes: 2

Views: 3001

Answers (1)

lukasgeiter
lukasgeiter

Reputation: 153140

The problem is that if after a route parameter comes one of these characters: /,;.:-_~+*=@|, you can't use it inside that route parameter because Laravel adjusts the regex to exclude that parameter.

I believe the reason for this is a scenario like: test/{foo}-{bar}

That means you could obviously change your URL to not use - inside the route parameter, or specify the regex condition that applies to the tournamentName yourself using where():

Route::any('tournament/{sportName}/{regionName}/{tournamentName}-odds',
         array('as' => 'tournament-page', 'uses' => 'HomeController@tournament')
     )->where('tournamentName', '[^\/]+');

Upvotes: 6

Related Questions