koel/app/Models/PlaylistCollaborationToken.php

40 lines
971 B
PHP
Raw Normal View History

2024-01-18 11:13:05 +00:00
<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
2024-01-18 11:13:05 +00:00
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 string $playlist_id
2024-01-18 11:13:05 +00:00
* @property Playlist $playlist
*/
class PlaylistCollaborationToken extends Model
{
use HasFactory;
2024-01-18 11:13:05 +00:00
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());
}
}