-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathJsonField.php
More file actions
35 lines (31 loc) · 1.08 KB
/
JsonField.php
File metadata and controls
35 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace ProcessMaker\Query;
use Illuminate\Database\Query\Grammars\MySqlGrammar;
use Illuminate\Database\Query\Grammars\SQLiteGrammar;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Query\Exceptions\UnsupportedQueryGrammarException;
class JsonField extends BaseField
{
public function toArray()
{
return [
'JsonField' => $this->field,
];
}
public function toEloquent($connection = null)
{
if (!$connection) {
$connection = DB::connection();
}
$grammar = $connection->getQueryGrammar();
// Convert to Laravel Database Json Syntax
$value = str_replace('.', '->', $this->field);
if (is_a($grammar, MySqlGrammar::class)) {
return $connection->raw((new Grammars\MySqlGrammar($connection))->wrapJsonSelector($value));
} elseif (is_a($grammar, SQLiteGrammar::class)) {
return $connection->raw((new Grammars\SQLiteGrammar($connection))->wrapJsonSelector($value));
} else {
throw new UnsupportedQueryGrammarException();
}
}
}