with(['application', 'user', 'position', 'pusatMengundi', 'saluranMengundi', 'attendance']) ->where('pusat_mengundi_id', $pusatMengundi->id) ->where('status', 'active') ->orderBy('position_id') ->orderBy('saluran_mengundi_id') ->get(); $fileName = 'attendance-'.$pusatMengundi->code.'-'.now()->format('Ymd-His').'.xlsx'; $path = 'exports/attendance/'.$fileName; Storage::disk('local')->makeDirectory('exports/attendance'); $absolutePath = Storage::disk('local')->path($path); $this->export->write($assignments, $absolutePath); $log = ExportLog::query()->create([ 'election_id' => $pusatMengundi->election_id, 'generated_by_user_id' => $actor->id, 'generated_at' => now(), 'report_type' => 'attendance_detail_by_pusat', 'filter_parameters' => [ 'pusat_mengundi_id' => $pusatMengundi->id, 'pusat_mengundi_code' => $pusatMengundi->code, ], 'file_name' => $fileName, 'disk' => 'local', 'path' => $path, ]); activity('exports') ->performedOn($log) ->causedBy($actor) ->withProperties([ 'report_type' => 'attendance_detail_by_pusat', 'pusat_mengundi_id' => $pusatMengundi->id, 'row_count' => $assignments->count(), ]) ->log('attendance_export_generated'); return $log; } }