Search in json column not working in laravel - laravel

I have one table which contains json string column ,i want to search inside the json column for that i am using whereJsonContains method but still it’s showing empty records but the data is there .did i miss anything .
$id=98; $reqid=7; Table::whereJsonContains(“json_data->”.$id ,$reqid)->get();
My json data is {“94”:”3”,”98”:”7”}
I was trying to fetch that column data and make it an array but it’s taking more time to execute so i want to do in query level for that i tried with whereJsonContains

I am not sure about whereJsonContains but following way will work
$result = Table::where(“json_data->$id” ,$reqid)->get();
dd($result);

Related

Search specific key's value from a json field database entry using eloquent

Hello everyone please I am working on a system and need to add a query that receives a search term stored with the variable $search and fetch all matching values for a specific key in a json field from database.
I have tried the code bellow
$query = Book::whereJsonContains('book_details->author',['like'=>"%{$search}%"])->get();
Book is my model, book_details is the json field name and author is the key. I want to retrieve every book with authors related to the search term
In Laravel, you can perform a query that retrieves all matching values for a specific key in a JSON field by utilizing the whereJsonContains method. A revised version of your code could look like this:
$query = Book::whereJsonContains('book_details->author', $search)->get();
This query will return all Book records where the value of the author key in the book_details JSON field contains the search term stored in the $search variable.
Note that you don't need to wrap the search term in % characters, as the whereJsonContains method performs a case-insensitive search for matching values by default.

Use a Field value in a Query (Seblod Query plugin)

I'm using the Query plugin that lets me create a Query field on my List & Search.
I have a hidden field with ID 'id_number' which I'm trying to use in my query. When I check the Page Source(Ctrl+U on Chrome), the hidden field has the correct value of id_number which is '22865'.
The part of my Query is-
WHERE [MATCH]p.pid||$cck->getValue('id_number')[/MATCH] AND (ban_reason in ("", "active"))
When I print this query out using the Debugger, the Query is using the literal value and querying the above as-
(p.pid LIKE '%$cck->getValue(\'id\_number\')%') ....and not like (p.pid LIKE '%22865%')
I also tried using $fields['id_number']->value but it still queries it incorrectly.
Should I not use $cck->getValue('id_number') to get the value of the hidden field in the query? Or is there something other than this that I need to use?

How to search using Table API

I want to figure out how to search a table's field for a keyword and return the rows that match. i.e. search for the word apple in the description field on a post table.
https://docs.servicenow.com/bundle/newyork-application-development/page/integrate/inbound-rest/concept/c_TableAPI.html#r_TableAPI-GET
If you are using ServiceNow TABLE API to fetch results then you could the following on any column of any table. All you need to do is to use sysparm_query parameter with CONTAINS keyword on the column that you are trying to search.
For example:
I want to fetch all the incidents that contains unable to connect string in the descriptions.
https://myinstance.service-now.com/api/now/v2/table/incident?sysparm_query=descriptionCONTAINSunable+to+connect
It returned all the incidents records that contains unable to connect string in there descriptions.

Get a data from SQL as a json

can you tell me how to make
DB::table()->where()->get() result into a JSON script?. In this script I want get a row as a result
DB::table('users')->get()->toJson() should be enough. Ref docs
If you are making API, use Eloquent resource.

Getting results from Hbase table using "like" like functionality

I am trying to get all row keys which match a particular pattern from Hbase table. The rowkey are present in a particular format as abc:def:ghi.
I am trying to write a java code which would get me all row keys starting with "abc". If any one can give me some idea , by using filter or any other method we can obtain the same . That would be very grateful.
Thanks
Ashit

Resources