2017-09-12 16 views
0

経路の引数は2つを渡したいが、1つのみを引数として渡したい。 以下は私のコードです。例について複数の場所を経路に渡す方法Laravel 5.4

Route::group(['domain' => '{subdomain}'.'.example.com'], function() { 

    // Here goes all your subdomain handling 

    // Then handle subdomain requests that where not found 
    Route::get('{slug}', function($subdomain, $slug) { 
     return redirect(\URL::to('http://example.com/'.$slug)); 
    })->where('slug', 'admin')->where('slug', 'distributor'); 
}); 

www.ez.example.com/distributorリダイレクト

しかしadminwww.example.com/distributorには、それだけ分配のために働いている

が動作していません。

答えて

2

あなたがどこの場所で動作するようになっている理由は、どこに配列が格納され、それに渡した名前(つまり、'slug')であるためです。 )ので、2番目のものが1番目のものを上書きします。

Routewhere()方法は、あなたが行うことができますので、どのような正規表現をとりです:

Route::get('{slug}', function($subdomain, $slug) { 
    return redirect(\URL::to('http://example.com/'.$slug)); 
})->where('slug', 'admin|distributor'); 

は、この情報がお役に立てば幸い!

+0

ありがとうございます。出来た。 @ロス – mayur

関連する問題