This database engine does not support JSON contains operations.

  1. public function __construct(?string $name = null, array $data = [], string $dataName = '')
  2. {
  3. parent::__construct($name, $data, $dataName);
  4.  
  5. $this->iWannaMethodJsonContainsInSqlite();
  6. }
  7.  
  8. public function iWannaMethodJsonContainsInSqlite()
  9. {
  10. \Illuminate\Database\Connection::resolverFor('sqlite', function ($connection, $database, $prefix, $config) {
  11. return new class($connection, $database, $prefix, $config) extends \Illuminate\Database\SQLiteConnection
  12. {
  13. protected function getDefaultQueryGrammar()
  14. {
  15. $this->getPdo()->sqliteCreateFunction('JSON_CONTAINS', function ($json, $val, $path = null) {
  16. $array = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
  17. $val = trim($val, '"');
  18. if ($path) {
  19. return $array[$path] == $val;
  20. }
  21.  
  22. return in_array($val, $array, false);
  23. });
  24.  
  25. return new class extends \Illuminate\Database\Query\Grammars\SQLiteGrammar
  26. {
  27. protected function compileJsonContains($column, $value)
  28. {
  29. [$field, $path] = $this->wrapJsonFieldAndPath($column);
  30. return 'json_contains(' . $field . ', ' . $value . $path . ')';
  31. }
  32. };
  33. }
  34. };
  35. });
  36. }
  37.  

And thanks: https://stackoverflow.com/questions/50535778/php-testing-json-contains-with-sqlite/50536534

Комментарии

Популярные сообщения из этого блога

Bitrix: кнопка добавить в корзину

Битрикс: какого х*я ты ищешь в неактивных разделах

Битрикс: highloadblock значения в свойстве список