raw() ); $businessId = 1779; Work::inRandomOrder()->take(150)->update(['business_id' => $businessId]); $projects = [3566, 3567, 3568]; foreach ($projects as $projectId) { Work::where('business_id', $businessId) ->whereNotIn('project_id', $projects) ->take(50)->update(['project_id' => $projectId, 'started_at' => \Carbon\Carbon::now()]); } $works = Work::where('business_id', $businessId)->get(); foreach ($works as $work){ \DB::table('works')->where('id', $work->id) ->update(['started_at' => \Carbon\Carbon::now()->subDays(rand(0,90))]); } } }