2019-12-29 08:02:26 -05:00
|
|
|
<?php namespace BookStack\Api;
|
|
|
|
|
2019-12-29 21:16:07 -05:00
|
|
|
use BookStack\Auth\User;
|
2019-12-29 08:02:26 -05:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-12-29 21:16:07 -05:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2019-12-30 09:51:28 -05:00
|
|
|
use Illuminate\Support\Carbon;
|
2019-12-29 08:02:26 -05:00
|
|
|
|
|
|
|
class ApiToken extends Model
|
|
|
|
{
|
|
|
|
protected $fillable = ['name', 'expires_at'];
|
2019-12-29 12:03:52 -05:00
|
|
|
protected $casts = [
|
2019-12-29 14:46:46 -05:00
|
|
|
'expires_at' => 'date:Y-m-d'
|
2019-12-29 12:03:52 -05:00
|
|
|
];
|
2019-12-29 21:16:07 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the user that this token belongs to.
|
|
|
|
*/
|
|
|
|
public function user(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
}
|
2019-12-30 09:51:28 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
}
|
2019-12-29 08:02:26 -05:00
|
|
|
}
|