Skip to content
This repository was archived by the owner on Jan 27, 2020. It is now read-only.

Commit 1a2f9d0

Browse files
authored
Merge pull request #4 from mbouclas/jsonAsUtf8
Add JSON_UNESCAPED_UNICODE as an option to the default Laravel json_encode
2 parents 823a2bd + efb0b92 commit 1a2f9d0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Translatable.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
namespace Themsaid\Multilingual;
44

5+
/**
6+
* Class Translatable
7+
* @package Themsaid\Multilingual
8+
*/
59
trait Translatable
610
{
11+
712
/**
813
* @param string $key
914
* @return mixed
@@ -68,4 +73,21 @@ protected function isJsonCastable($key)
6873

6974
return parent::isJsonCastable($key);
7075
}
76+
77+
/**
78+
* Alter default Laravel behaviour when it comes to json_encode.
79+
* This will save the json as UTF-8 to the DB
80+
*
81+
* @param $value
82+
* @return string
83+
*/
84+
protected function asJson($value)
85+
{
86+
$mode = JSON_UNESCAPED_UNICODE;
87+
if (isset($this->jsonAsUtf) && $this->jsonAsUtf == false){
88+
$mode = 0;
89+
}
90+
91+
return json_encode($value, $mode);
92+
}
7193
}

0 commit comments

Comments
 (0)