optimizations
This commit is contained in:
65
app/Models/NovaCardChallenge.php
Normal file
65
app/Models/NovaCardChallenge.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class NovaCardChallenge extends Model
|
||||
{
|
||||
public const STATUS_DRAFT = 'draft';
|
||||
public const STATUS_ACTIVE = 'active';
|
||||
public const STATUS_COMPLETED = 'completed';
|
||||
public const STATUS_ARCHIVED = 'archived';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'slug',
|
||||
'title',
|
||||
'description',
|
||||
'prompt',
|
||||
'rules_json',
|
||||
'status',
|
||||
'official',
|
||||
'featured',
|
||||
'winner_card_id',
|
||||
'entries_count',
|
||||
'starts_at',
|
||||
'ends_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'rules_json' => 'array',
|
||||
'official' => 'boolean',
|
||||
'featured' => 'boolean',
|
||||
'entries_count' => 'integer',
|
||||
'starts_at' => 'datetime',
|
||||
'ends_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function winnerCard(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(NovaCard::class, 'winner_card_id');
|
||||
}
|
||||
|
||||
public function entries(): HasMany
|
||||
{
|
||||
return $this->hasMany(NovaCardChallengeEntry::class, 'challenge_id');
|
||||
}
|
||||
|
||||
public function cards(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(NovaCard::class, 'nova_card_challenge_entries', 'challenge_id', 'card_id')
|
||||
->withPivot(['user_id', 'status', 'note'])
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user