在登录Laravel后返回到指定的URL,可以通过以下步骤实现: 首先,在Laravel中,用户登录通常是通过使用Auth门面来处理的。确保你已经在控制器或路由中引入了Auth门面。 在登录表单中,添加一个隐藏字段来存储要返回的URL。例如,可以在登录表单中添加如下代码:其中$redirect是一个变量,用于存储要返回的URL。 在登录控制器中...
重定向响应是Illuminate\Http\RedirectResponse类的实例,其中包含了必须的头信息将用户重定向到另一个URL。辅助函数redirect返回的就是RedirectResponse类的实例。 示例路由: Route::get('testRedirect','UserController@testRedirect'); 示例动作: publicfunctiontestRedirect(){// 以下示例代码为此处实现} 简单的重定向 ...
If your controller route requires parameters, you may pass them as the second argument to the action method:return redirect()->action( 'UserController@profile', ['id' => 1] );Redirecting With Flashed Session Data#Redirecting to a new URL and flashing data to the session are usually done ...
phpclassUsers_ControllerextendsBase_Controller{publicfunctionaction_index(){return"Welcome to the users controller."; } } 我们的users控制器是一个类,其名称是由其中包含的方法的域构成的,并以_Controller为后缀。由于这个控制器的域是用户帐户,我们的控制器被命名为Users_Controller。_Controller后缀是必需的,因...
The intended method provided by Laravel's redirector will redirect the user to the URL they were attempting to access before being intercepted by the authentication middleware. A fallback URI may be given to this method in case the intended destination is not available....
By type-hinting the Illuminate\Http\Request object, you may gain convenient access to the authenticated user from any controller method in your application via the request's user method:1<?php 2 3namespace App\Http\Controllers; 4 5use Illuminate\Http\RedirectResponse; 6use Illuminate\Http\...
还可以为 controller action指定路由名称: Route::get('user/profile',array('as'=>'profile','uses'=>'UserController@showProfile')); 现在,你可以使用路由名称来创建URL和重定向: $url=URL::route('profile'); $redirect=Redirect::route('profile'); ...
默认情况下,Laravel 将响应它收到的所有请求,而不管 HTTP 请求的 Host 头的内容如何。此外,在 web 请求期间生成应用程序的绝对 URL 时,将使用 Host 头的值。通常,您应该将 web 服务器(如 Nginx 或 Apache)配置为只向应用程序发送与给定主机名匹配的请求。但是,如果您无法直接自定义 web 服务器,并且需要指示...
在第一个控制器中,您应该执行以下操作: return redirect(route('routeToSecondController', [*your data*])); 如果能贴出来就更好了。不应在第二个控制器中添加多个参数...
public function home() { return redirect()->action('App\Http\Controllers\HomeController@home',['id'=>17]); } 使用会话数据重定向我们还可以在控制器方法中用路由或url重定向时传递闪过的会话消息,如下所示。 public function home() { return redirect('home')->with('message', 'Welcome to PHP.cn...