CourseWork/app/Console/Commands/AddScores.php
m.zargarov c7fefd138a Fix
2024-06-25 00:52:48 +04:00

44 lines
1019 B
PHP

<?php
namespace App\Console\Commands;
use App\Models\Grade;
use Illuminate\Console\Command;
class AddScores extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:add-scores {grade}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Add 4 and 5 scores for students';
/**
* Execute the console command.
*/
public function handle()
{
$grade = Grade::firstWhere('id', $this->argument('grade'));
$grade->students->random(7)->each(function ($student) {
$student
->lessons()
->syncWithPivotValues($student->lessons()->pluck('id'), ['score' => 4]);
});
$grade->students->random(5)->each(function ($student) {
$student
->lessons()
->syncWithPivotValues($student->lessons()->pluck('id'), ['score' => 5]);
});
}
}