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