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
18 class ApiToken extends Model implements Loggable
20 protected $fillable = ['name', 'expires_at'];
22 'expires_at' => 'date:Y-m-d'
26 * Get the user that this token belongs to.
28 public function user(): BelongsTo
30 return $this->belongsTo(User::class);
34 * Get the default expiry value for an API token.
35 * Set to 100 years from now.
37 public static function defaultExpiry(): string
39 return Carbon::now()->addYears(100)->format('Y-m-d');
45 public function logDescriptor(): string
47 return "({$this->id}) {$this->name}; User: {$this->user->logDescriptor()}";