mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 05:14:46 +02:00

* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Traits;
|
|
|
|
use Illuminate\Support\Str;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use App\Models\ApiKey;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use App\Extensions\Laravel\Sanctum\NewAccessToken;
|
|
|
|
/**
|
|
* @mixin \App\Models\Model
|
|
*/
|
|
trait HasAccessTokens
|
|
{
|
|
use HasApiTokens {
|
|
tokens as private _tokens;
|
|
createToken as private _createToken;
|
|
}
|
|
|
|
public function tokens(): HasMany
|
|
{
|
|
return $this->hasMany(Sanctum::$personalAccessTokenModel);
|
|
}
|
|
|
|
/**
|
|
* @param ?string[] $ips
|
|
*/
|
|
public function createToken(?string $memo, ?array $ips): NewAccessToken
|
|
{
|
|
/** @var \App\Models\ApiKey $token */
|
|
$token = $this->tokens()->forceCreate([
|
|
'user_id' => $this->id,
|
|
'key_type' => ApiKey::TYPE_ACCOUNT,
|
|
'identifier' => ApiKey::generateTokenIdentifier(ApiKey::TYPE_ACCOUNT),
|
|
'token' => $plain = Str::random(ApiKey::KEY_LENGTH),
|
|
'memo' => $memo ?? '',
|
|
'allowed_ips' => $ips ?? [],
|
|
]);
|
|
|
|
return new NewAccessToken($token, $plain);
|
|
}
|
|
}
|