Files
backend-umra/app/Models/Group.php

58 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/**
* @property date $start_date
* @property date $end_date
* @property Pilgrim[] $pilgrims
* @property Carbon $created_at
* @property Carbon $updated_at
*/
class Group extends Model
{
use HasFactory;
/**
* @var array<string, string>
*/
protected $casts = [
'start_date' => 'date',
'end_date' => 'date',
];
/**
* Get the name of the group
*
* @return Attribute
* */
public function name(): Attribute
{
return Attribute::make(
get: fn ($value) => $this->start_date->format('d M') . ' - ' . $this->end_date->format('d M'),
);
}
public function pilgrims(): HasMany
{
return $this->hasMany(Pilgrim::class);
}
public function leaderTeacher(): BelongsTo
{
return $this->belongsTo(Teacher::class, 'leader_teacher_id');
}
public function helperTeachers(): BelongsToMany
{
return $this->belongsToMany(Teacher::class, 'group_teacher');
}
}