File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
src/Picqer/Carriers/SendCloud Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ class Parcel extends Model
3131{
3232 use Query \Findable;
3333 use Persistance \Storable;
34+ use Persistance \Multiple;
3435
3536 protected $ fillable = [
3637 'id ' ,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Picqer \Carriers \SendCloud \Persistance ;
4+
5+ use Picqer \Carriers \SendCloud \Connection ;
6+
7+ /**
8+ * Trait Multiple
9+ *
10+ * @method Connection connection()
11+ *
12+ * @package Picqer\Carriers\SendCloud\Persistance
13+ */
14+ trait Multiple
15+ {
16+ public function saveMultiple (array $ models )
17+ {
18+ $ resultModels = [];
19+ $ results = $ this ->insertMultiple ($ models );
20+ foreach ($ results [$ this ->namespaces ['plural ' ]] as $ result )
21+ {
22+ $ resultModels [] = new static ($ this ->connection (), $ result );
23+ }
24+ return $ resultModels ;
25+ }
26+
27+ public function insertMultiple (array $ models )
28+ {
29+ $ json = [];
30+ $ json [$ this ->namespaces ['plural ' ]] = [];
31+ foreach ($ models as $ model )
32+ {
33+ $ json [$ this ->namespaces ['plural ' ]][] = $ model ->attributes ();
34+ }
35+
36+ return $ this ->connection ()->post ($ this ->url , json_encode ($ json ));
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments