In the distance learning system, the collection of statistical data on the passing of tests by users. Statistics, at the moment, is displayed in one common table.

/** Π€ΠΎΡ€ΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ статистики **/ $data = []; foreach($users as $user) { $id = $user->id; $data[$id] = [ 'fio' => $user->last_name.' '.$user->first_name.' '.$user->second_name, ]; /** Входная статистика */ $stat = Result::whereRaw('user_id = '.$id.' and exam_id = '.$enter_exam->id)->latest()->first(); $data = $this->addStat($stat, $data, $id, 'course', 'enter'); /** Π—Π°ΠΊΠ»ΡŽΡ‡ΠΈΡ‚Π΅Π»ΡŒΠ½Π°Ρ статистика */ $stat = Result::whereRaw('user_id = '.$id.' and exam_id = '.$finish_exam->id)->latest()->first(); $data = $this->addStat($stat, $data, $id, 'course', 'finish'); /** Бтатистика ΠΏΠΎ ЛСкциям */ if(count($lectures)) { foreach($lectures as $lecture) { $exam = $lecture->exam()->firstOrFail(); $stat = Result::whereRaw('user_id = '.$id.' and exam_id = '.$exam->id)->latest()->first(); $data = $this->addStat($stat, $data, $id, 'lectures', $lecture->slug); } } else { $data[$id]['lectures'] = null; } 

At the end of the course, it is required to save the statistics data to a file and place it on the server, for further downloading by the administrator if necessary.

  • The question is not complete. What format to save? and what exactly does not work? You do not know how to save data to a file? - ExileeD
  • @Exileed Yes, that's right, I do not understand how to save the received data. Save in any format, so that the administrator can download the resulting label and then print it out if necessary. I don’t understand how: Statistics obtained data- > Save to file-> Save to server and output to admin area - bastadien
  • I will answer with the answer. the trial didn't fit - ExileeD

1 answer 1

The algorithm is approximately as follows.

  1. Get data from the database.
  2. Save to file output.

You can do so Configure the file system.

Add to config/filesystems.php

 'disks' => [ 'csv' => [ 'driver' => 'local', 'root' => storage_path().'/csv', ], ], 

And save the data to a file this way.

 Storage::disk('csv')->put('file.csv', $content); $content = Storage::disk('csv')->get('file.csv'); 

Read through Storage too

  1. Make a router that id reads this file and gives it to the client. (or better along the ramdom line to eliminate brute force)