get(); $now = Carbon::now(); $notifications = $users->map(function (User $user) use ($now, $article) { $notification = [ 'id' => Uuid::uuid4()->toString(), 'type' => ArticleTitleNotification::class, 'notifiable_id' => $user->id, 'notifiable_type' => get_class($user), 'data' => json_encode((new ArticleTitleNotification($article))->toArray($user), JSON_UNESCAPED_UNICODE), 'created_at' => $now, 'updated_at' => $now, ]; return $notification; }); $size = 1000; foreach (array_chunk($notifications->all(), $size, true) as $chunk) { // 通知 DatabaseNotification::query()->insert($chunk); } }); } }