@@ -119,7 +119,8 @@ public function showAction(Request $request, $record)
119
119
public function updateAction (Request $ request , $ record )
120
120
{
121
121
$ record = $ record instanceof Model ? $ record : $ this ->findModelInstance ($ record );
122
- $ record ->update ((array ) $ request ->input ('data.attributes ' ));
122
+ $ record ->fill ((array ) $ request ->input ('data.attributes ' ));
123
+ $ record ->save ();
123
124
124
125
if ($ relationships = $ request ->input ('data.relationships ' )) {
125
126
$ this ->updateRecordRelationships ($ record , (array ) $ relationships );
@@ -171,20 +172,21 @@ public function relationshipAction(Request $request, $record, $relation)
171
172
* @param Request $request
172
173
* @param Model|int $record
173
174
* @param string $relation
174
- * @param string|null $foreignKey
175
175
*
176
176
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
177
177
*
178
178
* @return JsonApiResponse
179
179
*/
180
- public function updateToOneRelationshipAction (Request $ request , $ record , $ relation, $ foreignKey = null )
180
+ public function updateToOneRelationshipAction (Request $ request , $ record , $ relation )
181
181
{
182
182
abort_if (!array_key_exists ($ relation , $ this ->getModelRelationships ()), Response::HTTP_NOT_FOUND );
183
183
184
184
$ record = $ record instanceof Model ? $ record : $ this ->findModelInstance ($ record );
185
+ $ relation = $ this ->getModelRelationships ()[$ relation ];
185
186
$ data = (array ) $ request ->input ('data ' );
186
187
187
- $ record ->update ([($ foreignKey ?: $ relation . '_id ' ) => $ data ['id ' ]]);
188
+ $ record ->{$ relation ->getForeignKey ()} = $ data ['id ' ];
189
+ $ record ->save ();
188
190
189
191
return new JsonApiResponse ();
190
192
}
@@ -335,7 +337,8 @@ protected function updateRecordRelationships($record, array $relationships)
335
337
$ data = $ relationship ['data ' ];
336
338
337
339
if ($ relation instanceof BelongsTo) {
338
- $ record ->update ([$ relation ->getForeignKey () => $ data ['id ' ]]);
340
+ $ record ->{$ relation ->getForeignKey ()} = $ data ['id ' ];
341
+ $ record ->save ();
339
342
} else if ($ relation instanceof BelongsToMany) {
340
343
$ record ->{$ name }()->sync (array_pluck ($ data , 'id ' ));
341
344
}
0 commit comments