Php Laravel卡在身份验证循环中
我陷入了一个认证循环,我一生都无法理解为什么Php Laravel卡在身份验证循环中,php,laravel,laravel-routing,Php,Laravel,Laravel Routing,我陷入了一个认证循环,我一生都无法理解为什么 Route::get('/', function() { return View::make('hello'); //return 'Hello ' . Auth::user()->first_name . '!'; }); Route::get('/login', function() { return View::make('login'); }); Route::post('/login', function
Route::get('/', function()
{
return View::make('hello');
//return 'Hello ' . Auth::user()->first_name . '!';
});
Route::get('/login', function() {
return View::make('login');
});
Route::post('/login', function() {
// @TODO: Validate the login details!
Auth::attempt(array(
'email' => Input::get('email'),
'password' => Input::get('password')
));
return Redirect::to('/');
});
Route::group(array('before' => 'auth'), function() {
Route::get('/home', function()
{
//return View::make('hello');
return 'Hello ' . Auth::user()->first_name . '!';
});
/*
|--------------------------------------------------------------------------
| API Route Handlers
|--------------------------------------------------------------------------
|
| The API Routes.
|
*/
Route::group(array('prefix' => 'api/v1'), function() {
Route::resource('events', 'EventsController');
});
});
以下是事件的顺序:
我转到localhost:8000/home
它工作并将我重定向到/login
然后我继续登录
它会将我重定向到/
,如果我随后转到/home
,它仍然会将我转到/login
理想情况:
转到/home
仅重定向到/login
然后我登录
它将我重定向到/
然后,我可以在/
和/home
之间自由移动,而不用担心登录
编辑1
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->string('password');
$table->string('first_name');
$table->string('last_name');
$table->string('id_number')->unique();
$table->enum('user_type', array('option 1', 'option 2', 'option 3'));
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
修复了它-问题是未设置
Auth::trunt()
的值
这是我的新代码更新版本
Route::get('/', function()
{
return View::make('hello');
//return 'Hello ' . Auth::user()->first_name . '!';
});
Route::get('/login', function() {
return View::make('login');
});
Route::post('/login', function() {
// @TODO: Validate the login details!
$valid = Auth::attempt(array(
'email' => Input::get('email'),
'password' => Input::get('password')
));
if ($valid)
{
return Redirect::to('/home');
}
else
{
return Redirect::to('/');
}
});
Route::group(array('before' => 'auth'), function() {
Route::get('/home', function()
{
//return View::make('hello');
return 'Hello ' . Auth::user()->first_name . '!';
});
/*
|--------------------------------------------------------------------------
| API Route Handlers
|--------------------------------------------------------------------------
|
| The API Routes.
|
*/
Route::group(array('prefix' => 'api/v1'), function() {
Route::resource('events', 'EventsController');
});
});
看起来用户从未登录。能否检查
Auth::trunt
的返回值?(应该是true
)Auth::trunt()返回什么?你没有检查它是否真的成功not@lukasgeiter@Damien Prisydd(Auth::trust())==bool(false)
这要看情况而定。如果您有默认的app/config/auth.php
,您需要一个。(但是默认的Laravel安装也附带了一个模型)请检查app/config/auth.php
中的“驱动程序”是否设置为eloquent
或数据库
正常。您能检查输入(input
和密码
)是否正确吗?