3.3Laravel控制器(Controller)之重定向(Redirect)

redirect()帮助器函数

路由web文件

Route::redirect('/here', '/there');

命名路由

Route::get(
    '/user/profile',
    [UserProfileController::class, 'show']
)->name('profile');
return redirect()->route('profile');

模型参数路由

// For a route with the following URI: /profile/{id}

return redirect()->route('profile', [$user]);

控制器行为路由

use App\Http\Controllers\UserController;

return redirect()->action([UserController::class, 'index']);

外部域路由

return redirect()->away('https://www.google.com');

闪现会话路由

Route::post('/user/profile', function () {
    // ...

    return redirect('dashboard')->with('status', 'Profile updated!');
});

redirectTo()函数

用户验证

/**
 * Get the path the user should be redirected to.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return string
 */
protected function redirectTo($request)
{
    return route('login');
}

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/php/laravel/5438.html

发表评论

登录后才能评论