Skip to content

Commit

Permalink
change req
Browse files Browse the repository at this point in the history
  • Loading branch information
shellrean authored and shellrean committed Jan 14, 2023
1 parent e131830 commit 38adc7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/Api/v1/PenilaianController.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ public function storeNilaiEsayExcel(Request $request)
]);

try {
Excel::import(new JawabanPesertaEsayImport(), $request->file('file'));
$user = $request->user();
Excel::import(new JawabanPesertaEsayImport($user), $request->file('file'));
} catch (\Exception $e) {
return SendResponse::internalServerError('kesalahan 500.'.$e->getMessage());
}
Expand Down
11 changes: 8 additions & 3 deletions app/Imports/JawabanPesertaEsayImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@

class JawabanPesertaEsayImport implements ToCollection, WithStartRow
{
public function collection(Collection $rows)
private $user;

public function __construct($user)
{
$user = request()->user('api');
$this->user = $user;
}

public function collection(Collection $rows)
{
$jawaban_peserta_ids = [];
foreach($rows as $row) {
if($row->filter()->isNotEmpty()) {
Expand Down Expand Up @@ -95,7 +100,7 @@ public function collection(Collection $rows)
'banksoal_id' => $jawab->banksoal_id,
'peserta_id' => $jawab->peserta_id,
'jawab_id' => $jawab->id,
'corrected_by' => $user->id,
'corrected_by' => $this->user->id,
'point' => $row[4],
'created_at' => now(),
'updated_at' => now()
Expand Down

0 comments on commit 38adc7c

Please sign in to comment.