Conflicting Routes between Blog and Pages

Posted 4 years ago by andrewclark

Hey,

Laracasts has taught me an awful lot and improved my programming massively but I'm having a bit of an issue with a CMS I'm working on. I've a feeling that having the flu is not helping me and I could be missing something simple but any help would be appreciated.

The code below shows my routes for the blog section and static pages section of my site - as you can tell, they conflict. How do I go about avoiding this conflict whilst retaining the routes?

I don't want to prefix the news and blog areas with /news/ as that would virtually duplicate some segments and unnecessarily lengthens the URL, for example /news/members-news/article-title

Is there an easy way for me to check whether the NewsController returns a valid response otherwise direct the request to the PagesController?

// News & Blogs
Route::get('{section}/{slug?}', [
        'uses' => 'NewsController@index',
        'as'   => 'news'
    ]);

// Static Pages Routes
Route::get('{parent}/{page?}/{child?}/{subchild?}/{anotherchild?}', [
    'as'   => 'page.show',
    'uses' => 'PagesController@show'
]);

Please sign in or create an account to participate in this conversation.