我没有使用来自 App\User 的默认 laravel 身份验证。
以下是我的代码
应用\模型\用户
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);
}
}
配置\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 并引用这个 url