2026-05-29 00:33:00 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-05-30 02:50:34 +03:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
use Illuminate\Support\Str;
|
2026-05-29 00:33:00 +03:00
|
|
|
|
|
|
|
|
class UserList extends Model
|
|
|
|
|
{
|
2026-05-30 02:50:34 +03:00
|
|
|
protected $fillable = ['user_id', 'title', 'slug', 'description', 'is_public'];
|
|
|
|
|
|
|
|
|
|
protected $casts = ['is_public' => 'boolean'];
|
|
|
|
|
|
|
|
|
|
protected static function boot(): void
|
|
|
|
|
{
|
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
|
|
static::creating(function (UserList $list) {
|
|
|
|
|
if (empty($list->slug)) {
|
|
|
|
|
$list->slug = Str::slug($list->title);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function user(): BelongsTo { return $this->belongsTo(User::class); }
|
|
|
|
|
|
|
|
|
|
public function listGames(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(UserListGame::class, 'user_list_id')->orderBy('order');
|
|
|
|
|
}
|
2026-05-29 00:33:00 +03:00
|
|
|
}
|