From 6a4b84be2c34182331b59d1cd4b2e50cc3bd4364 Mon Sep 17 00:00:00 2001 From: Kwaku Ofori Apeadu Date: Fri, 12 Apr 2019 19:38:43 +0000 Subject: [PATCH] Fixes array cast incompatibility For models with an array cast, the attributesToArray() method returns the cast array instead of the serialized array. So usage of `markApproved(), markRejected(), markPostponed() and markPending()` methods of the `Moderatable` trait throw a DB exception due to the attempt to save the raw array instead of the serialized array. So this fix changes the `$new->attributesToArray()` used in the mentioned methods to `$new->attributes`. --- src/Moderatable.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Moderatable.php b/src/Moderatable.php index a4bd65f..cd6b4d9 100644 --- a/src/Moderatable.php +++ b/src/Moderatable.php @@ -62,7 +62,7 @@ public static function postpone($id) public function markApproved() { $new = (new static)->newQueryWithoutScope(new ModerationScope())->approve($this->id); - return $this->setRawAttributes($new->attributesToArray()); + return $this->setRawAttributes($new->attributes); } /** @@ -73,7 +73,7 @@ public function markApproved() public function markRejected() { $new = (new static)->newQueryWithoutScope(new ModerationScope())->reject($this->id); - return $this->setRawAttributes($new->attributesToArray()); + return $this->setRawAttributes($new->attributes); } /** @@ -84,7 +84,7 @@ public function markRejected() public function markPostponed() { $new = (new static)->newQueryWithoutScope(new ModerationScope())->postpone($this->id); - return $this->setRawAttributes($new->attributesToArray()); + return $this->setRawAttributes($new->attributes); } /** @@ -95,7 +95,7 @@ public function markPostponed() public function markPending() { $new = (new static)->newQueryWithoutScope(new ModerationScope())->pend($this->id); - return $this->setRawAttributes($new->attributesToArray()); + return $this->setRawAttributes($new->attributes); } /**