2024-05-13 16:44:00 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Models\Lesson;
|
|
|
|
|
2024-06-16 12:20:48 +04:00
|
|
|
class ScoreService
|
2024-05-13 16:44:00 +04:00
|
|
|
{
|
2024-06-16 12:20:48 +04:00
|
|
|
public function update(Lesson $lesson, array $data)
|
2024-05-13 16:44:00 +04:00
|
|
|
{
|
2024-06-16 12:20:48 +04:00
|
|
|
$lesson->students->each(function ($item, $key) use ($data, $lesson) {
|
2024-05-27 16:57:28 +04:00
|
|
|
if ($data['score' . $item->id]) {
|
2024-06-16 12:20:48 +04:00
|
|
|
$lesson->students()->syncWithoutDetaching([$item->id => ['score' => $data['score' . $item->id]]]);
|
2024-05-27 16:57:28 +04:00
|
|
|
}
|
|
|
|
});
|
2024-05-13 16:44:00 +04:00
|
|
|
|
2024-06-16 12:20:48 +04:00
|
|
|
return $lesson;
|
2024-05-13 16:44:00 +04:00
|
|
|
}
|
|
|
|
}
|