Eloquent 모델 또는 쿼리 빌더에서 insert() 메서드를 호출하여 컬렉션 에 여러 문서를 삽입할 수 있습니다.
여러 문서를 삽입하려면 insert() 메서드를 호출하고 메서드 호출 내에서 새 문서를 배열로 지정합니다. 각 배열 항목에는 단일 문서의 필드 값이 포함됩니다.
예시
다음 Eloquent 및 Query Builder 탭에서 선택하여 각 해당 쿼리 구문을 사용하는 동일한 작업에 대한 사용 예제를 볼 수 있습니다.
이 예에서는 다음 조치를 수행합니다.
- MovieEloquent 모델을 사용하여- sample_mflix데이터베이스의- movies컬렉션을 나타냅니다.
- movies컬렉션에 문서를 삽입합니다.
- 삽입 작업의 성공 여부를 출력합니다. 
이 예시 insert() 메서드를 호출하여 2023에 개봉된 영화를 나타내는 문서를 삽입합니다. 삽입 작업이 성공적인 하면 1 값을 반환합니다. 작업이 실패하면 예외가 발생합니다.
$success = Movie::insert([     [         'title' => 'Anatomy of a Fall',         'release_date' => new UTCDateTime(new DateTimeImmutable('2023-08-23')),     ],     [         'title' => 'The Boy and the Heron',         'release_date' => new UTCDateTime(new DateTimeImmutable('2023-12-08')),     ],     [         'title' => 'Passages',         'release_date' => new UTCDateTime(new DateTimeImmutable('2023-06-28')),     ], ]); echo 'Insert operation success: ' . ($success ? 'yes' : 'no'); 
Insert operation success: yes 
이 예에서는 다음 조치를 수행합니다.
- DB파사드에서- table()메서드를 호출하여- movies컬렉션 에 액세스합니다.
- movies컬렉션에 문서를 삽입합니다.
- 삽입 작업의 성공 여부를 출력합니다. 
이 예시 insert() 메서드를 호출하여 2023에 개봉된 영화를 나타내는 문서를 삽입합니다. 삽입 작업이 성공적인 하면 1 값을 반환합니다. 작업이 실패하면 예외가 발생합니다.
$success = DB::table('movies')     ->insert([         [             'title' => 'Anatomy of a Fall',             'release_date' => new UTCDateTime(new DateTimeImmutable('2023-08-23')),         ],         [             'title' => 'The Boy and the Heron',             'release_date' => new UTCDateTime(new DateTimeImmutable('2023-12-08')),         ],         [             'title' => 'Passages',             'release_date' => new UTCDateTime(new DateTimeImmutable('2023-06-28')),         ],     ]); echo 'Insert operation success: ' . ($success ? 'yes' : 'no'); 
Insert operation success: yes 
Laravel 애플리케이션을 편집하여 사용 예제를 실행하는 방법을 알아보려면 사용 예제 랜딩 페이지를 참조하세요.