PHP code example of daccess1 / yii2-json-query-helper
1. Go to this page and download the library: Download daccess1/yii2-json-query-helper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
daccess1 / yii2-json-query-helper example snippets
use daccess1\JSONQueryHelper\JSONQueryHelper;
Model::find()->where(JSONQueryHelper::JSONContains(['json_column', [123, 'value_2']]))->all();
//Check if single value is present in JSON
JSONQueryHelper::JSONContains(['json_column', 'value_1'])
//Check if any of values is present in JSON
JSONQueryHelper::JSONContains(['or', 'json_column', ['value_1', 'value_2' ... 'value_n']])
//Equivalent shorthand
JSONQueryHelper::JSONContains(['json_column', ['value_1', 'value_2' ... 'value_n']])
//Check if all values is present in JSON
JSONQueryHelper::JSONContains(['and', 'json_column', ['value_1', 'value_2' ... 'value_n']])
//Check if single value is present in JSON field in path 'values'
JSONQueryHelper::JSONContains(['and', ['json_column', '$.values'], ['value_1', 'value_2']])
//This expression will be generated by the code above
JSON_CONTAINS(`json_column`, "value_1", "$.values") AND JSON_CONTAINS(`json_column`, "value_2", "$.values")
//You can specify path with any usage cases shown in examples above, like this
JSONQueryHelper::JSONContains([['json_column', '$.values'], 'value_1'])
JSONQueryHelper::JSONContains([['json_column', '$.values'], ['value_1', 'value_2' ... 'value_n']])
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.