phase 5
This commit is contained in:
@@ -9,8 +9,10 @@ use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
@@ -52,4 +54,21 @@ class User extends Authenticatable
|
||||
['email_enabled' => true, 'database_enabled' => true, 'muted' => false],
|
||||
);
|
||||
}
|
||||
|
||||
public function tokens(): MorphMany
|
||||
{
|
||||
return $this->morphMany(PersonalAccessToken::class, 'tokenable');
|
||||
}
|
||||
|
||||
public function createToken(string $name, array $abilities = ['*'], ?\DateTimeInterface $expiresAt = null): PersonalAccessToken
|
||||
{
|
||||
$token = Str::random(64);
|
||||
|
||||
return $this->tokens()->create([
|
||||
'name' => $name,
|
||||
'token' => hash('sha256', $token),
|
||||
'abilities' => $abilities,
|
||||
'expires_at' => $expiresAt,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user