laravel两条路线非常相似,呼叫另一条路线

Hi there I have two routes that look identical except that one has an extra paramter called genre how do make them call their on routines and not have them mixed up.

Route::get('browse/{product_slug}', array(
    'as' => 'products.view_by_producttype', 
    function($slug)         
    {   
    }
))->where('product_slug', '[A-Za-z\-]+');

Route::get('browse/{producttype_slug}/{genre_slug}', array(
    'as' => 'products.view_by_producttype_genre', 
    function($productype_slug, $genre_slug) 
    {       
    }   
))->where('producttype_slug', '[A-Za-z\-]+')->where('genre_slug', '[A-Za-z\-]+');

Upated Code and order:

Route::get('browse/{producttype_slug}', array(
    'as' => 'products.view_by_producttype', 
    function($producttype_slug)         
    { 
        $producttype = ProductTypes::where('slug', '=', $producttype_slug)->firstOrFail();      

        $items = DB::table('products')->join('productvariations', function($join) {
            $join->on('productvariations.product_id', '=', 'products.id');
        })->where('producttype_id', '=', $producttype->id)->paginate(1);

        return View::make('products.view_by_producttype')->with(compact('items', 'producttype'));

    }
))->where('producttype_slug', '[A-Za-z\-]+');


Route::get('browse/{producttype_slug}/{genre_slug}', array(
    'as' => 'products.view_by_producttype_genre', 
    function($producttype_slug, $genre_slug) 
    { 
        $producttype = ProductTypes::where('slug', '=', $producttype_slug)->firstOrFail();

        $genre = GenreTypes::where('slug', '=', $genre_slug)->firstOrFail();

        $items = DB::table('products')->join('product_genretypes', function($join) {
            $join->on('product_genretypes.product_id', '=', 'products.id');             
        })->join('productvariations', function($join) {
            $join->on('productvariations.product_id', '=', 'products.id');
        })
        ->where('genretype_id', '=', $genre->id)
        ->where('producttype_id', '=', $producttype->id)
        ->paginate(1);

        return View::make('products.view_by_type_genre')->with(compact('items', 'producttype', 'genre'));

    }   
))->where('producttype_slug', '[A-Za-z\-]+')->where('genre_slug', '[A-Za-z\-]+');

Just swap the order - have the Genre route defined first - like this:

Route::get('browse/{producttype_slug}/{genre_slug}', array(
    'as' => 'products.view_by_producttype_genre', 
    function($productype_slug, $genre_slug) 
    {       
    }   
))->where('producttype_slug', '[A-Za-z\-]+')->where('genre_slug', '[A-Za-z\-]+');

Route::get('browse/{product_slug}', array(
    'as' => 'products.view_by_producttype', 
    function($product_slug)         
    {   
    }
))->where('product_slug', '[A-Za-z\-]+');

That way - if a route matches with a Genre route - it will be used first.

Otherwise it will default back to the normal Product route.