]> BookStack Code Mirror - bookstack/blob - app/Api/ApiToken.php
Added support for Fortran language
[bookstack] / app / Api / ApiToken.php
1 <?php namespace BookStack\Api;
2
3 use BookStack\Auth\User;
4 use Illuminate\Database\Eloquent\Model;
5 use Illuminate\Database\Eloquent\Relations\BelongsTo;
6 use Illuminate\Support\Carbon;
7
8 class ApiToken extends Model
9 {
10     protected $fillable = ['name', 'expires_at'];
11     protected $casts = [
12         'expires_at' => 'date:Y-m-d'
13     ];
14
15     /**
16      * Get the user that this token belongs to.
17      */
18     public function user(): BelongsTo
19     {
20         return $this->belongsTo(User::class);
21     }
22
23     /**
24      * Get the default expiry value for an API token.
25      * Set to 100 years from now.
26      */
27     public static function defaultExpiry(): string
28     {
29         return Carbon::now()->addYears(100)->format('Y-m-d');
30     }
31 }