Skip to content

Commit

Permalink
Serialize Translator model using json_encode (#3894)
Browse files Browse the repository at this point in the history
* Add the feature to serialize the Translator model using json_encode

* Update Translator.php
  • Loading branch information
marijnz0r authored and emptynick committed Feb 23, 2019
1 parent 6e4f171 commit 7581c84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"larapack/doctrine-support": "~0.1.4",
"arrilot/laravel-widgets": "^3.7",
"league/flysystem": "~1.0.41",
"larapack/voyager-hooks": "~1.0.5"
"larapack/voyager-hooks": "~1.0.5",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpcov": "~3.0|~4.0",
Expand Down
10 changes: 9 additions & 1 deletion src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

use ArrayAccess;
use Illuminate\Database\Eloquent\Model;
use JsonSerializable;
use TCG\Voyager\Facades\Voyager as VoyagerFacade;

class Translator implements ArrayAccess
class Translator implements ArrayAccess, JsonSerializable
{
protected $model;
protected $attributes = [];
Expand Down Expand Up @@ -316,4 +317,11 @@ public function runTranslatorMethod($method, array $arguments)

return call_user_func_array([$this->model, $method], $arguments);
}

public function jsonSerialize()
{
return array_map(function ($array) {
return $array['value'];
}, $this->getRawAttributes());
}
}

0 comments on commit 7581c84

Please sign in to comment.