여러 배열이있는 Laravel에 데이터를 저장하려고합니다.
배열은 다음과 같습니다.
Array
(
[0] => Array
(
[client_personnel_name] => Ron
[client_id] => 52
[client_personnel_email] => [email protected]
)
[1] => Array
(
[client_personnel_name] => John
[client_id] => 52
[client_personnel_email] => [email protected]
)
)
이 데이터를 저장할 때 :
$personnel = ClientsPersonnel::create($client_personnel);
$personnel->save();
디버깅시 삽입하기 위해 생성되는 데이터. 이것은 전송 된 데이터가 저장되는 속성에서 얻는 것입니다.
[attributes:protected] => Array
(
[updated_at] => 2015-04-23 06:53:05
[created_at] => 2015-04-23 06:53:05
[id] => 2
)
여러 어레이가있는 데이터를 어떻게 저장할 수 있습니까?
다음 DB::insert()
과 같이 사용할 수 있습니다 .
DB::table('client_personnel')->insert(array($client_personnel));
대안으로 루프를 사용하여이 작업을 수행 할 수 있습니다.
foreach ($personnels as $personnelAttributes) {
$personnel = new ClientsPersonnel($personnelAttributes);
$personnel->save();
}
문안 인사,
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다