]> BookStack Code Mirror - bookstack/blob - app/Api/ApiToken.php
Apply fixes from StyleCI
[bookstack] / app / Api / ApiToken.php
1 <?php
2
3 namespace BookStack\Api;
4
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;
10
11 /**
12  * Class ApiToken.
13  *
14  * @property int    $id
15  * @property string $token_id
16  * @property string $secret
17  * @property string $name
18  * @property Carbon $expires_at
19  * @property User   $user
20  */
21 class ApiToken extends Model implements Loggable
22 {
23     protected $fillable = ['name', 'expires_at'];
24     protected $casts = [
25         'expires_at' => 'date:Y-m-d',
26     ];
27
28     /**
29      * Get the user that this token belongs to.
30      */
31     public function user(): BelongsTo
32     {
33         return $this->belongsTo(User::class);
34     }
35
36     /**
37      * Get the default expiry value for an API token.
38      * Set to 100 years from now.
39      */
40     public static function defaultExpiry(): string
41     {
42         return Carbon::now()->addYears(100)->format('Y-m-d');
43     }
44
45     /**
46      * @inheritdoc
47      */
48     public function logDescriptor(): string
49     {
50         return "({$this->id}) {$this->name}; User: {$this->user->logDescriptor()}";
51     }
52 }