Redirect::back() 在 laravel 4 中返回一个空的 url
Redirect::back() returning an empty url in laravel 4
我想在验证用户身份后将用户重定向回输入 url
场景是:用户输入 url,在后端我检查用户是否已通过身份验证,如果用户未通过身份验证,则重定向用户登录 url 并在成功登录后将用户重定向回第一个 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');
}
请帮助 me.I 我是 Laravel 的新手。
使用 Redirect::intended('/');
而不是 Redirect::back();
。
PS: 也改
Route::filter('logged', function($request)
{
if(!Auth::check())
return Redirect::guest(URL::to('users')); //Your login form.
});
使用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.
示例:return Redirect::intended('/');
我想在验证用户身份后将用户重定向回输入 url 场景是:用户输入 url,在后端我检查用户是否已通过身份验证,如果用户未通过身份验证,则重定向用户登录 url 并在成功登录后将用户重定向回第一个 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');
}
请帮助 me.I 我是 Laravel 的新手。
使用 Redirect::intended('/');
而不是 Redirect::back();
。
PS: 也改
Route::filter('logged', function($request)
{
if(!Auth::check())
return Redirect::guest(URL::to('users')); //Your login form.
});
使用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.
示例:return Redirect::intended('/');