我想在验证用户后将用户重定向回输入的URL 方案是:用户输入网址,在后端我检查用户是否经过身份验证,如果用户未通过身份验证,则将用户重定向到登录网址,并在成功登录后将用户重定向回用户输入的第一个网址
用户控制器:
public function index()
{
if(!Auth::check())
{
return View::make('adminLogin');
}
return Redirect::to('admin');
}
public function login()
{
$creds = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
if (Auth::attempt($creds))
return Redirect::back();
}
routes.php文件:
Route::resource('users', 'UsersController');
Route::post('login', 'UsersController@login');
filters.php:
Route::filter('logged', function($request)
{
if(!Auth::check())
return Redirect::to('users');
});
SettingController.php:
public function __construct()
{
$this->beforeFilter('logged', array('only' => array('index')));
}
public function index()
{
return View::make('setting');
}
请帮助我。我是Laravel的新手。
答案 0 :(得分:1)
使用Redirect::intended('/');
代替Redirect::back();
。
PS:也改变
Route::filter('logged', function($request)
{
if(!Auth::check())
return Redirect::guest(URL::to('users')); //Your login form.
});
答案 1 :(得分:0)
使用as.POSIXct(value/1000, tz = "UTC", origin="1970-01-01 00:00:00")
[1] "50175-08-15 19:31:27.300048 UTC"
方法
intended()
示例:The intended method on the 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.