]> BookStack Code Mirror - bookstack/blobdiff - app/Api/ApiToken.php
Move logFailedAccess into Activity
[bookstack] / app / Api / ApiToken.php
index 4ea12888e56bde8a381a34c88d3b00028c1fedb2..523c3b8b80ec2a883e590b73cbf701d2d7e67829 100644 (file)
@@ -1,6 +1,9 @@
 <?php namespace BookStack\Api;
 
+use BookStack\Auth\User;
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Support\Carbon;
 
 class ApiToken extends Model
 {
@@ -8,4 +11,21 @@ class ApiToken extends Model
     protected $casts = [
         'expires_at' => 'date:Y-m-d'
     ];
+
+    /**
+     * Get the user that this token belongs to.
+     */
+    public function user(): BelongsTo
+    {
+        return $this->belongsTo(User::class);
+    }
+
+    /**
+     * Get the default expiry value for an API token.
+     * Set to 100 years from now.
+     */
+    public static function defaultExpiry(): string
+    {
+        return Carbon::now()->addYears(100)->format('Y-m-d');
+    }
 }