Skip to content

Commit af3ba80

Browse files
committed
Implemented JsonSerializable for better usage of json_encode on eloquent models.
1 parent bf24d3d commit af3ba80

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

Eloquent/Translate.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
<?php
22

33
namespace Kiberzauras\Translator\Eloquent;
4+
use JsonSerializable;
45
use Kiberzauras\Translator\Translator;
56

67
/**
78
* Class Translate
89
* @package Kiberzauras\Translator\Eloquent
910
* @author Rytis Grincevičius <[email protected]>
1011
*/
11-
class Translate {
12+
class Translate implements JsonSerializable {
1213

1314
/**
1415
* @var string
1516
*/
16-
private $translations = [
17-
'en'=>'empty'
18-
];
17+
private $translations = [];
1918
private $locale;
2019
private $enforce = false;
2120

@@ -42,6 +41,18 @@ public function __toString()
4241
return $this->get();
4342
}
4443

44+
/**
45+
* Specify data which should be serialized to JSON
46+
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
47+
* @return mixed data which can be serialized by <b>json_encode</b>,
48+
* which is a value of any type other than a resource.
49+
* @since 5.4.0
50+
*/
51+
public function jsonSerialize()
52+
{
53+
return $this->get();
54+
}
55+
4556
/**
4657
* @return string
4758
* @author Rytis Grincevičius <[email protected]>
@@ -98,4 +109,4 @@ public function plural($number = 0)
98109
{
99110
return $this;
100111
}
101-
}
112+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Translatable Eloquent's for Laravel 5",
44
"keywords": ["laravel", "multilanguage", "kiberzauras", "translations", "eloquent"],
55
"license": "MIT",
6-
"time": "2016-04-21 14:14",
6+
"time": "2016-05-03 14:07",
77
"authors": [
88
{
99
"name": "Rytis Grincevicius",

0 commit comments

Comments
 (0)