Skip to content

Commit

Permalink
Use Arrayable interface when casting to array
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tricks authored Sep 13, 2024
1 parent 5398fa8 commit 9e0b828
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/TranslatableFieldMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Outl1ne\NovaTranslatable;

use Exception;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;
use Laravel\Nova\Fields\Markdown;
use Laravel\Nova\Fields\Textarea;
Expand Down Expand Up @@ -44,7 +45,11 @@ public function translatable()
try {
if (!is_array($value)) {
if (is_object($value)) {
$value = (array) $value;
if($value instanceof Arrayable) {
$value = $value->toArray();
} else {
$value = (array) $value;
}
} else {
$testValue = json_decode($value, true);
if (is_array($testValue)) $value = $testValue;
Expand Down

0 comments on commit 9e0b828

Please sign in to comment.