-<?php namespace BookStack\Api;
+<?php
-use BookStack\Auth\User;
-use BookStack\Interfaces\Loggable;
+namespace BookStack\Api;
+
+use BookStack\Activity\Models\Loggable;
+use BookStack\Users\Models\User;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
/**
- * Class ApiToken
- * @property int $id
+ * Class ApiToken.
+ *
+ * @property int $id
* @property string $token_id
* @property string $secret
* @property string $name
* @property Carbon $expires_at
- * @property User $user
+ * @property User $user
*/
class ApiToken extends Model implements Loggable
{
+ use HasFactory;
+
protected $fillable = ['name', 'expires_at'];
protected $casts = [
- 'expires_at' => 'date:Y-m-d'
+ 'expires_at' => 'date:Y-m-d',
];
/**
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function logDescriptor(): string
{
return "({$this->id}) {$this->name}; User: {$this->user->logDescriptor()}";
}
+
+ /**
+ * Get the URL for managing this token.
+ */
+ public function getUrl(string $path = ''): string
+ {
+ return url("/api-tokens/{$this->user_id}/{$this->id}/" . trim($path, '/'));
+ }
}