3 namespace BookStack\Api;
5 use BookStack\Auth\User;
6 use BookStack\Interfaces\Loggable;
7 use Illuminate\Database\Eloquent\Model;
8 use Illuminate\Database\Eloquent\Relations\BelongsTo;
9 use Illuminate\Support\Carbon;
15 * @property string $token_id
16 * @property string $secret
17 * @property string $name
18 * @property Carbon $expires_at
19 * @property User $user
21 class ApiToken extends Model implements Loggable
23 protected $fillable = ['name', 'expires_at'];
25 'expires_at' => 'date:Y-m-d',
29 * Get the user that this token belongs to.
31 public function user(): BelongsTo
33 return $this->belongsTo(User::class);
37 * Get the default expiry value for an API token.
38 * Set to 100 years from now.
40 public static function defaultExpiry(): string
42 return Carbon::now()->addYears(100)->format('Y-m-d');
48 public function logDescriptor(): string
50 return "({$this->id}) {$this->name}; User: {$this->user->logDescriptor()}";