如何将路由组前缀重定向到其他页面

时间:2017-10-23 06:26:11

标签: php laravel

我有这个:

Route::group(['prefix'=>'manager', 'middleware' => ['auth' , 'CheckAdmin']  ] , function(){

route::get('/' , function(){
        return redirect()->back();
});

route::get('/dashboard' , 'ManagerController@index');
route::post('/sendpharmacy' , 'ManagerController@sendph');

});

我的checkadmin中间件看起来像:

if(auth()->check()) {
    if(auth()->user()->isAdmin())
            return $next($request);
    }

    return redirect('/pharmacist/dashboard');
}

我想重定向/管理器到其他页面,但返回404错误。 请帮帮我。

3 个答案:

答案 0 :(得分:1)

试试这个

Route::group(['prefix'=>'manager', 'middleware' => ['auth' , 'CheckAdmin']  ] , function() {

    Route::get('/' , function(){
        return redirect()->action('ManagerController@index');
    });

    Route::get('/dashboard' , 'ManagerController@index');
    Route::post('/sendpharmacy' , 'ManagerController@sendph');

});

或者您可以跳过重定向

Route::group(['prefix'=>'manager', 'middleware' => ['auth' , 'CheckAdmin'] ] , function() {
    Route::get('/' ,              'ManagerController@index');
    Route::get('/dashboard' ,     'ManagerController@index');
    Route::post('/sendpharmacy' , 'ManagerController@sendph');
});

如果您获得404,则需要检查CheckAdmin中间件。

答案 1 :(得分:0)

如果您只想将/manager重定向到/manager/dashboard(查看您的评论),那么您可以这样做:

Route::group(['prefix'=>'manager' ] , function() {
    Route::get('/', function () {
        return redirect('manager/dashboard');
    });

    Route::get('/dashboard', 'ManagerController@index');
    ...
});

文档通常会回答大多数问题。

https://laravel.com/docs/5.5/redirects

答案 2 :(得分:0)

我解决了这个问题 只需更改位置重定向行:)

route::get('/manager' , function(){
        return redirect()->back();
});

Route::group(['prefix'=>'manager', 'middleware' => ['auth' , 'CheckAdmin']  ] , function(){
route::get('/dashboard' , 'ManagerController@index');
route::post('/sendpharmacy' , 'ManagerController@sendph');

});

谢谢大家帮助:D