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]); }); } }