【发布时间】:2018-04-11 13:42:32
【问题描述】:
我想在验证用户后将用户重定向回输入的 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');
});
设置控制器.php:
public function __construct()
{
$this->beforeFilter('logged', array('only' => array('index')));
}
public function index()
{
return View::make('setting');
}
请帮助我。我是 Laravel 的新手。
【问题讨论】:
标签: laravel laravel-4.2