publicfunctionredirectToPage(Request$request){// 根据条件进行重定向if($condition1){returnredirect()->route('page1');}elseif($condition2){returnredirect()->route('page2');}else{returnredirect()->route('page3');}} 在上面
Route::get('/user/{id}', function ($id) { // 处理逻辑 })->name('user.profile'); 在控制器或路由闭包中,使用redirect()函数来重定向到带有变量的路由: 代码语言:txt 复制 return redirect()->route('user.profile', ['id' => $userId]); 这里的$userId是一个变量,可以根据实际情况进行替换。
重定向响应是类Illuminate\Http\RedirectResponse的实例, 包含了重定向用户到其他 URL 所需要的合适头信息。有很多方式生成RedirectResponse实例。最简单的方法是使用全局的redirect辅助函数: Route::get('dashboard',function(){returnredirect('home/dashboard');}); ...
Route::get('user/profile',function(){ // })->name('profile'); ->name(‘xxx’) 为路由命名 为路由指定了名称后,就可以使用全局辅助函数route来生成链接或重定向到该路由 //生成URL.. $url = route('profile'); //生成重定向 return redirect()->route('profile'); Route::get('user/{id}/pro...
return'Hello World'; }); 基本POST 路由 Route::post('foo/bar',function() { return'Hello World'; }); 注册一个可以响应任何HTTP动作的路由 Route::any('foo',function() { return'Hello World'; }); 仅支持HTTPS的路由 Route::get('foo',array('https',function() ...
Route::get('testRedirect', 'UserController@testRedirect'); 示例动作controller: public function testRedirect() { // 以下示例代码放在这个地方 } 1. 简单的重定向 假设我们当前的域名为:http://localhost return redirect('home'); 重定向到 http://localhost/home ...
return back(); // 跳转到上一页 return redirect(' /posts/{$post->id} '); // 重定向方法 return redirect('/post'); // 路由的方法 return redirect()->route('articleList'); route('articleList')//命名路由直接在 route 中定义过了
在Laravel中,redirect默认重定向方式为临时迁移,http状态码是302 直接地址: return redirect('/home'); 用路由名字: return redirect()->route('route.name'); 跳转上一个页面: return redirect()->back(); 有时候我们提交from表单的时候,可能会提交失败,如果失败了,又不想重新填写一遍,这样我们就需要用到携带...
return \Redirect::route('regions')->with('message', 'State saved correctly!!!'); 问题是我不知道如何传递 {id} 参数,它应该在我的 URL 中。 谢谢你。 您可以将路由参数作为第二个参数传递给route(): return \Redirect::route('regions', [$id])->with('message', 'State saved correctly!!!')...
$url = route('profile'); // 正在生成重定向... return redirect()->route('profile');如果命名路由定义了参数,您可以将参数作为第二个参数传递给 route 函数。 给定的参数将自动插入到生成的 URL 的正确位置:Route::get('/user/{id}/profile', function ($id) { // })->name('profile'); $url...