diff --git a/app/Actions/YearEndProcedures/RecordHistoricalSeats.php b/app/Actions/YearEndProcedures/RecordHistoricalSeats.php new file mode 100644 index 0000000..fee9460 --- /dev/null +++ b/app/Actions/YearEndProcedures/RecordHistoricalSeats.php @@ -0,0 +1,34 @@ +saveSeats(); + } + + public function saveSeats(): void + { + $seats = Seat::all(); + foreach ($seats as $seat) { + $student_id = $seat->student->id; + $year = Carbon::now()->year; + $seat_description = $seat->ensemble->name.' - '.$seat->audition->name.' - '.$seat->seat; + HistoricalSeat::create([ + 'student_id' => $student_id, + 'year' => $year, + 'seat_description' => $seat_description, + ]); + } + } +} diff --git a/app/Models/HistoricalSeat.php b/app/Models/HistoricalSeat.php index cff2db9..7403cff 100644 --- a/app/Models/HistoricalSeat.php +++ b/app/Models/HistoricalSeat.php @@ -10,6 +10,8 @@ class HistoricalSeat extends Model { use HasFactory; + protected $guarded = []; + public function student(): BelongsTo { return $this->belongsTo(Student::class);