Skip to content

Instantly share code, notes, and snippets.

@hmic
Last active October 27, 2015 15:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmic/559151cda085e082cc74 to your computer and use it in GitHub Desktop.
Save hmic/559151cda085e082cc74 to your computer and use it in GitHub Desktop.
<?php
namespace App\Model\Table;
trait saveAllTrait {
public function saveAll($entities = [], $options = null) {
if($options === null) {
return array_map([$this, 'save'], $entities);
}
$saved_entities = [];
foreach($entities as $entity) {
$entity = $this->save($entity, $options);
$this->eventManager()->dispatch(
new Event('Model.saveAll', $this, ['result' => $entity])
);
$saved_entities[] = $entity;
}
return $saved_entities;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment