From 095881761c84421132dee40615453b80deba15bb Mon Sep 17 00:00:00 2001 From: Matt Young Date: Thu, 29 May 2025 11:10:15 -0500 Subject: [PATCH] Add action to save seats to historical table. --- .../RecordHistoricalSeats.php | 34 +++++++++++++++++++ app/Models/HistoricalSeat.php | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 app/Actions/YearEndProcedures/RecordHistoricalSeats.php 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);