59 lines
1.5 KiB
PHP
59 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Services\DoublerService;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
|
|
class Student extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
public function school(): BelongsTo
|
|
{
|
|
return $this->belongsTo(School::class);
|
|
}
|
|
|
|
public function users(): HasManyThrough
|
|
{
|
|
return $this->hasManyThrough(
|
|
User::class, // The target model we want to access
|
|
School::class, // The intermediate model through which we access the target model
|
|
'id', // The foreign key on the intermediate model
|
|
'school_id', // The foreign key on the target model
|
|
'school_id', // The local key
|
|
'id' // The local key on the intermediate model
|
|
);
|
|
}
|
|
|
|
public function directors(): HasManyThrough
|
|
{
|
|
return $this->users();
|
|
}
|
|
|
|
public function entries(): HasMany
|
|
{
|
|
return $this->hasMany(Entry::class);
|
|
}
|
|
|
|
public function full_name(bool $last_name_first = false): string
|
|
{
|
|
if ($last_name_first) {
|
|
return $this->last_name.', '.$this->first_name;
|
|
}
|
|
|
|
return $this->first_name.' '.$this->last_name;
|
|
}
|
|
|
|
public function doublerRequests(): HasMany
|
|
{
|
|
return $this->hasMany(DoublerService::class);
|
|
}
|
|
}
|