44 lines
1019 B
PHP
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]);
|
|
});
|
|
}
|
|
}
|