7
7
use BackedEnum ;
8
8
use Illuminate \Database \Eloquent \Builder ;
9
9
use Illuminate \Database \Eloquent \Collection ;
10
- use Illuminate \Support \Collection as BaseCollection ;
11
10
use Illuminate \Database \Eloquent \Model ;
12
11
use Illuminate \Database \Eloquent \Relations \BelongsToMany as EloquentBelongsToMany ;
13
12
use Illuminate \Support \Arr ;
13
+ use Illuminate \Support \Collection as BaseCollection ;
14
14
use MongoDB \BSON \Binary ;
15
15
use MongoDB \BSON \ObjectId ;
16
16
17
17
use function array_diff ;
18
+ use function array_intersect ;
18
19
use function array_map ;
20
+ use function array_merge ;
19
21
use function array_values ;
20
22
use function assert ;
23
+ use function collect ;
21
24
use function count ;
22
25
use function in_array ;
23
26
use function is_numeric ;
@@ -112,7 +115,8 @@ public function create(array $attributes = [], array $joining = [], $touch = tru
112
115
/**
113
116
* Format the sync / toggle record list so that it is keyed by ID.
114
117
*
115
- * @param array $records
118
+ * @param array $records
119
+ *
116
120
* @return array
117
121
*/
118
122
protected function formatRecordsList ($ records ): array
@@ -133,8 +137,9 @@ protected function formatRecordsList($records): array
133
137
*
134
138
* Each existing model is detached, and non existing ones are attached.
135
139
*
136
- * @param mixed $ids
140
+ * @param mixed $ids
137
141
* @param bool $touch
142
+ *
138
143
* @return array
139
144
*/
140
145
public function toggle ($ ids , $ touch = true )
@@ -193,22 +198,23 @@ public function toggle($ids, $touch = true)
193
198
// Once we have finished attaching or detaching the records, we will see if we
194
199
// have done any attaching or detaching, and if we have we will touch these
195
200
// relationships if they are configured to touch on any database updates.
196
- if ($ touch && (count ($ changes ['attached ' ]) ||
197
- count ($ changes ['detached ' ]))) {
198
-
201
+ if (
202
+ $ touch && (count ($ changes ['attached ' ]) ||
203
+ count ($ changes ['detached ' ]))
204
+ ) {
199
205
$ this ->parent ->touch ();
200
206
$ this ->newRelatedQuery ()->whereIn ($ this ->relatedKey , $ ids )->touch ();
201
207
}
202
208
203
209
return $ changes ;
204
210
}
205
211
206
-
207
212
/**
208
213
* Sync the intermediate tables with a list of IDs or collection of models.
209
214
*
210
- * @param \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model|array $ids
211
- * @param bool $detaching
215
+ * @param \Illuminate\Support\Collection|Model|array $ids
216
+ * @param bool $detaching
217
+ *
212
218
* @return array
213
219
*/
214
220
public function sync ($ ids , $ detaching = true )
@@ -259,7 +265,7 @@ public function sync($ids, $detaching = true)
259
265
// ton of touch operations until we are totally done syncing the records.
260
266
foreach ($ records as $ id ) {
261
267
// Only non strict check if exist no update s possible beacause no attributtes
262
- if (!in_array ($ id , $ current )) {
268
+ if (! in_array ($ id , $ current )) {
263
269
$ this ->attach ($ id , [], false );
264
270
$ changes ['attached ' ][] = $ this ->castKey ($ id );
265
271
}
@@ -388,7 +394,6 @@ protected function buildDictionary(Collection $results)
388
394
389
395
foreach ($ results as $ result ) {
390
396
foreach ($ result ->$ foreign as $ item ) {
391
-
392
397
//Prevent if id is non keyable
393
398
if ($ item instanceof ObjectId) {
394
399
$ item = (string ) $ item ;
0 commit comments