我正在尝试为管理员用户创建登录系统,但Auth::trunt返回false。。。有人能帮我吗p我从四个月前就开始关注文档。拉雷维尔。com,但我似乎找不到解决方案。。。
public function auth()
{
$rules = [
'email' => 'required|email',
'password' => 'required',
];
$validator = Validator::make(Input::all(), $rules);
if ($validator->passes()) {
$credentials = [
'email' => Input::get('email'),
'password' => Input::get('password'),
'deleted_at' => null, // Extra voorwaarde
];
if (Auth::attempt($credentials)) {
return Redirect::to('/');
} else {
return Redirect::route('admin.login')
->withInput()
->with('auth-error-message', 'U heeft een onjuiste gebruikersnaam of een onjuist wachtwoord ingevoerd.');
}
} else {
return Redirect::route('admin.login') // Zie: $ php artisan routes
->withInput() // Vul het formulier opnieuw in met de Input.
->withErrors($validator); // Maakt $errors in View.
}
}
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class Admin extends Eloquent {
protected $table = 'admins';
protected $softDelete = true;
protected $hidden = [
'created_at',
'updated_at',
'deleted_at',
'password'
];
protected $fillable = [
'id',
'email',
'approved'
];
public function getAuthIdentifier()
{
return $this->getKey();
}
public function getAuthPassword()
{
return $this->password;
}
public function getReminderEmail()
{
return $this->email;
}
public static function boot()
{
parent::boot();
self::creating(function ($admin) {
$admin->password = Hash::make($admin->password);
});
}
}
public function up()
{
Schema::create('admins', function($table)
{
$table->increments('id');
$table->string('email','255')->unique();
$table->string('password','60');
$table->timestamps();
$table->softDeletes();
$table->timestamp('approved')->nullable();
});
}
提前感谢。HS.
您的auth.php
配置文件是否匹配不同的模型/表结构?
'model' => 'Admin';
'table' => 'admins';
此外,您没有protected$softDelete=true;
在您的管理模型中,但您正在用您的Auth::attempt();
检查它。看到http://laravel.com/docs/eloquent#soft-deleting.
好啊我终于自己弄明白了。我已将默认用户类的名称更改为“Admin”。由于laravel自动将UserInterface实现到用户模型,因此我需要在管理模型中手动实现它:
class Admin extends Eloquent implements UserInterface{
{
...
}
这就是它的全部...