【发布时间】:2014-01-22 09:26:56
【问题描述】:
我正在使用 Laravel 4.1 创建一个 api。对于身份验证,我想使用 Laravel Basic auth。每次我填写输入字段时,它都不让我进入。它只是清除输入并再次弹出表单。我不确定我做错了什么。我没有使用迁移来创建用户表。这只是一条基本路线:
Route::get('admin', function()
{
return "authenticated";
})->before('auth.basic');
这是我的过滤器:
Route::filter('auth.basic', function()
{
return Auth::basic('username');
});
这是我的用户模型:
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'pivot');
/**
* @var array
*/
protected $guarded = array('id', 'created_at', 'updated_at', 'is_admin');
protected $fillable = array('username', 'password', 'name_first', 'name_middle', 'name_last', 'email', 'address', 'city', 'state', 'zip_code', 'country', 'phone', 'title', 'profile_image', 'status');
/**
* @var array
*/
public static $rules = array();
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->password;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public function getReminderEmail()
{
return $this->email;
}
}
【问题讨论】:
-
@yannis 你能解决我的问题吗?