Mikkel Winther
Mikkel Winther

Reputation: 597

Laravel 4 routing problems

I'm having issues with my routes in my Laravel 4.1 website.

I have the following route for viewing blog posts and it seems to work just fine.

Route::get('/{slug}', array(

    'as' => 'post-slug',
    'uses' => 'PostController@get'

));

Any routes I have below this one seem to break, though.

I used to have my static pages like 'about', 'archive' etc. located below these lines of code in routes.php, but I discovered that the page would always display nothing unless I moved this to the bottom of the page. This works for me, but is obviously unsatisfactional.

Now I'm trying to implement browsing by post tags with the following code:

Route::get('/{tag-slug}', array(

    'as' => 'tag-slug',
    'uses' => 'PostController@getByTag'

));

However, this code isn't executed properly for some reason. I never enter the controller or the method within the controller. I checked with die(), which works directly in the route, but nowhere deeper.

EDIT

This is my link to the individual post route, which works fine:

{{ link_to_route('post-slug', 'COMMENTS ('.$post->comments->count().')', $post->slug) }}

And this is my link to the individual tag route, which doesn't work at all:

{{ link_to_route('tag-slug', strtoupper($tag->title), $tag->slug) }}

Upvotes: 0

Views: 428

Answers (1)

JustinHo
JustinHo

Reputation: 4745

your first route is a wildcard route, no matter how you specify like {slug} or {tag-slug}, they are the same thing, whichever comes last will be in effect. You have to make a route for tag like this: tag/{tag}, so it will be different than the {slug}.

Upvotes: 3

Related Questions