mirror of
https://github.com/koel/koel
synced 2024-12-20 17:43:36 +00:00
36 lines
862 B
PHP
36 lines
862 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Models;
|
||
|
|
||
|
use Carbon\Carbon;
|
||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||
|
use Illuminate\Database\Eloquent\Model;
|
||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
use Illuminate\Support\Str;
|
||
|
|
||
|
/**
|
||
|
* @property string $token
|
||
|
* @property Carbon $created_at
|
||
|
* @property-read bool $expired
|
||
|
* @property Playlist $playlist
|
||
|
*/
|
||
|
class PlaylistCollaborationToken extends Model
|
||
|
{
|
||
|
protected static function booted(): void
|
||
|
{
|
||
|
static::creating(static function (PlaylistCollaborationToken $token): void {
|
||
|
$token->token ??= Str::uuid()->toString();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public function playlist(): BelongsTo
|
||
|
{
|
||
|
return $this->belongsTo(Playlist::class);
|
||
|
}
|
||
|
|
||
|
protected function expired(): Attribute
|
||
|
{
|
||
|
return Attribute::get(fn (): bool => $this->created_at->addDays(7)->isPast());
|
||
|
}
|
||
|
}
|