我没有使用来自App \ User的默认laravel身份验证。
下面是我的代码
App \ Models \ User
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Hash;
use App\Http\Controllers\Helpers\SlugController;
use Laravel\Passport\HasApiTokens;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasApiTokens;
//
protected $table = 'users';
protected $visible = ['name', 'slug'];
protected $fillable =['name', 'slug', 'email', 'password'];
public function setSlugAttribute($value){
$slug = new SlugController;
$this->attributes['slug'] = !empty($value)?$slug->create($this, $value)
:$slug->create($this, $this->attributes['name']);
}
public function setPasswordAttribute($value){
$this->attributes['password'] = Hash::make($value);
}
}
config \ auth.php
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
app \ Providers \ AuthServiceProvider.php
public function boot()
{
$this->registerPolicies();
Passport::routes(); //Commenting this code works fine
Passport::tokensExpireIn(now()->addDays(15)); //Commenting this code works fine
Passport::refreshTokensExpireIn(now()->addDays(30)); //Commenting this code works fine
}
在AuthServiceProvider中,如果我在三行中添加注释,则会生成我的令牌,并且能够生成该令牌并为用户解析该令牌。
我也更改了用户迁移表。
数据库\迁移\ 2014_10_12_000000_create_users_table.php
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name', 50);
$table->string('slug', 60)->unique()->default('');
$table->string('email', 100)->unique();
$table->string('mobile', 10)->unique();
$table->text('password');
$table->boolean('is_blocked')->default(0);
$table->timestamps();
});
我删除了remember_token
,并添加了Slug,mobile和is_blocked。
需要澄清的是为什么我从passport:routes()得到错误。我该如何避免呢?
如何创建客户端ID。
我正在使用laravel 5.8并引用this url