whereJsonContains Laravel 5.6 not working?
The data types have to match:
// [1, 2]
->whereJsonContains('players', 1) // Works.
->whereJsonContains('players', '1') // Doesn't work.
// ["1", "2"]
->whereJsonContains('players', '1') // Works.
->whereJsonContains('players', 1) // Doesn't work.
Laravel whereIn implementation of whereJsonContains
You need to follow your query as below.
$array = [0 => 1, 1 => 2, 2 => 3];
// Eloquent
PaymentTransaction::whereJsonContains('payload->ProductCode->id',$array)->get();;
// or
PaymentTransaction::jsonContains('payload->ProductCode->id', $array)->get();
you can try it as below too.
$array = [0 => 1, 1 => 2, 2 => 3];
$array = array_values(array_map('strval',$array));
PaymentTransaction::where(function ($query) use ($array) {
foreach ($array as $id) {
$query->orWhereJsonContains('payload->ProductCode->id', $id);
}
})->get();
JSON_CONTAINS doesn't recognize my column mysql v.8.0.17 laravel 5.6
The problem is empty string that you are passing as argument.
Try:
SomeModel::whereRaw("JSON_CONTAINS(column, null, '$.a')")->get();
Get records from a table where an array of deleted_organization_id does not contain organization id using eloquent laravel 5.6
This is what you are looking.
$posts = Post::whereRaw("not json_contains(deleted_for_organization , '[".Auth::user()->organization_id."]') OR deleted_by_org is NULL")->get();
How can I select data write where in json object in related ORM Laravel
When you use with
in Laravel Eloquent, it doesn't grab the other table, it creates 2 queries, so you can't query like this.
You can use :
$basket = Basket::whereHas('product', function ($query) use ($stores_id) {
$query->whereJsonContains('store->id', $stores_id);
})->get();
Or use JOIN statement.
Related Topics
Simplexmlelement and Xpath, Getting Empty Array()
Phpunit: Doing Assertions on Non-Public Variables
In Simplexml, How to Add an Existing Simplexmlelement as a Child Element
PHP Get Height and Width in PDF File Proprieties
PHP Dynamic Db Page Rewrite Url
Laravel 5.3 - HTMLspecialchars() Expects Parameter 1 to Be String
How to Format a PHP Include() Absolute (Rather Than Relative) Path
How to Make a Select in PHP/MySQL Case Insensitive
Http Auth via PHP - PHP_Auth_User Not Set
Pdo's Rowcount() Not Working on PHP 5.2.6+
Zend Framework 2 - Removed Form Element Causes Validation to Fail
Php's Simplexml: How to Use Colons in Names
Laravel 5 Carbon Global Locale
How to Get the Total Found Rows Without Considering the Limit in Pdo