49 lines
1.0 KiB
PHP
49 lines
1.0 KiB
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)->with('student')->with('audition')->get();
|
|
}
|
|
|
|
public function getAcceptedEntry()
|
|
{
|
|
return Entry::find($this->accepted_entry);
|
|
}
|
|
|
|
// Find a doubler based on both keys
|
|
public static function findDoubler($studentId, $eventId)
|
|
{
|
|
return static::where('student_id', $studentId)
|
|
->where('event_id', $eventId)
|
|
->first();
|
|
}
|
|
}
|