2022-08-10 14:56:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2024-03-27 09:53:05 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
2022-08-10 14:56:01 +00:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property string $id
|
|
|
|
* @property string $name
|
|
|
|
* @property User $user
|
2024-04-18 11:27:07 +00:00
|
|
|
* @property Collection<array-key, Playlist> $playlists
|
2022-08-10 14:56:01 +00:00
|
|
|
* @property int $user_id
|
|
|
|
* @property Carbon $created_at
|
|
|
|
*/
|
|
|
|
class PlaylistFolder extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
public $incrementing = false;
|
|
|
|
protected $keyType = 'string';
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
|
2024-05-19 05:49:42 +00:00
|
|
|
protected $with = ['user'];
|
|
|
|
|
2022-08-10 14:56:01 +00:00
|
|
|
protected static function booted(): void
|
|
|
|
{
|
|
|
|
static::creating(static fn (self $folder) => $folder->id = Str::uuid()->toString());
|
|
|
|
}
|
|
|
|
|
2024-03-27 09:53:05 +00:00
|
|
|
public function playlists(): BelongsToMany
|
2022-08-10 14:56:01 +00:00
|
|
|
{
|
2024-03-27 09:53:05 +00:00
|
|
|
return $this->belongsToMany(Playlist::class, null, 'folder_id');
|
2022-08-10 14:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function user(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
}
|
2024-01-18 11:13:05 +00:00
|
|
|
|
|
|
|
public function ownedBy(User $user): bool
|
|
|
|
{
|
|
|
|
return $this->user_id === $user->id;
|
|
|
|
}
|
2022-08-10 14:56:01 +00:00
|
|
|
}
|