Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

Laravel using or inside routes to use multiple url as same as action

in Laravel i have this route group:

Route::prefix('panel')->group(function(){
    Route::get('/', AdminComponent::class);
    Route::get('/administrator', AdminComponent::class);
});

and my question is how can i combine this urls which they have the same behavior to open manage url

can i combine this routes to single route? for example:

Route::prefix('panel')->group(function(){
    Route::get('/|administrator', AdminComponent::class);
});
question from:https://stackoverflow.com/questions/65651885/laravel-using-or-inside-routes-to-use-multiple-url-as-same-as-action

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Maybe you could do something like this:

Route::prefix('panel')->group(function(){

    Route::get('/{url?}', function () {

        //redirect or return view here

    })->where(['url' => 'administrator']);

});

Adding another route like 'administrator2' would be:

->where(['url' => 'administrator|administrator2'])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...