3 namespace BookStack\Api;
5 use BookStack\Activity\Models\Loggable;
6 use BookStack\Users\Models\User;
7 use Illuminate\Database\Eloquent\Factories\HasFactory;
8 use Illuminate\Database\Eloquent\Model;
9 use Illuminate\Database\Eloquent\Relations\BelongsTo;
10 use Illuminate\Support\Carbon;
16 * @property string $token_id
17 * @property string $secret
18 * @property string $name
19 * @property Carbon $expires_at
20 * @property User $user
22 class ApiToken extends Model implements Loggable
26 protected $fillable = ['name', 'expires_at'];
28 'expires_at' => 'date:Y-m-d',
32 * Get the user that this token belongs to.
34 public function user(): BelongsTo
36 return $this->belongsTo(User::class);
40 * Get the default expiry value for an API token.
41 * Set to 100 years from now.
43 public static function defaultExpiry(): string
45 return Carbon::now()->addYears(100)->format('Y-m-d');
51 public function logDescriptor(): string
53 return "({$this->id}) {$this->name}; User: {$this->user->logDescriptor()}";