auditionadmin/app/Models/Doubler.php

44 lines
916 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Doubler extends Model
{
// Specify that we're not using a single primary key
protected $primaryKey = null;
public $incrementing = false;
protected $guarded = [];
protected $casts = [
'entries' => 'array',
];
public function student(): BelongsTo
{
return $this->belongsTo(Student::class);
}
public function event(): BelongsTo
{
return $this->belongsTo(Event::class);
}
public function entries()
{
return Entry::whereIn('id', $this->entries)->get();
}
// Find a doubler based on both keys
public static function findDoubler($studentId, $eventId)
{
return static::where('student_id', $studentId)
->where('event_id', $eventId)
->first();
}
}