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

Commit 333fb4f

Browse files
committed
Add JSON_UNESCAPED_UNICODE as an option to the default Laravel json_encode
1 parent 823a2bd commit 333fb4f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Translatable.php

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

33
namespace Themsaid\Multilingual;
44

5+
/**
6+
* Class Translatable
7+
* @package Themsaid\Multilingual
8+
*/
59
trait Translatable
610
{
11+
/**
12+
* Set to false to avoid setting the json_encode as utf8
13+
*
14+
* @var bool
15+
*/
16+
public $jsonAsUtf = true;
17+
718
/**
819
* @param string $key
920
* @return mixed
@@ -68,4 +79,17 @@ protected function isJsonCastable($key)
6879

6980
return parent::isJsonCastable($key);
7081
}
82+
83+
/**
84+
* Alter default Laravel behaviour when it comes to json_encode.
85+
* This will save the json as UTF-8 to the DB
86+
*
87+
* @param $value
88+
* @return string
89+
*/
90+
protected function asJson($value)
91+
{
92+
$mode = ( ! $this->jsonAsUtf) ? 0 : JSON_UNESCAPED_UNICODE;
93+
return json_encode($value, $mode);
94+
}
7195
}

0 commit comments

Comments
 (0)