48 lines
1006 B
PHP
48 lines
1006 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Support\Str;
|
|
|
|
class GameList extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'name',
|
|
'slug',
|
|
'description',
|
|
'is_default'
|
|
];
|
|
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(function ($list) {
|
|
$list->slug = Str::slug($list->name);
|
|
});
|
|
|
|
static::updating(function ($list) {
|
|
$list->slug = Str::slug($list->name);
|
|
});
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function games(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Game::class)
|
|
->with(['platforms'])
|
|
->withTimestamps();
|
|
}
|
|
}
|