What is that supposed to end with? Like how is the query supposed to look?
Laravel Query Value Need To Explode
Hi all , I have a laravel Query, where it has a value , i need to explode the vlaue and write a where condition. Her is the code
dd($appointments->whereIn([explode(' ','preference->appoint_info->location_dropdown')],'ssss')->get());
Can some one help me with these Thanks
^ Illuminate\Support\Collection {#1861 ▼
#items: array:68 [▼
0 => {#1851 ▼
+"id": "a3f81160-81fa-11eb-bc69-273474788a80"
+"first_name": "j"
+"phone": "999999999999"
+"email": "[email protected]"
+"status_code": null
+"state": 0
+"preference": "{"userinfo": {"age": "29", "dob": "1992-02-01", "dob_": {"day": "01", "year": "1992", "month": "02"}, "town": "m", "email": "[email protected]", "fname": "j", "lname": "j", "mname": "j", "_token": "TMsAYroACMUYWVrxBepWc1zVDBwZuM9Moc3740Zc", "action": "participant", "gender": "Male", "postcode": "m", "ethnicity": "Indian", "street_no": "m", "home_phone": "999999999999", "postal_code": "j", "street_name": "m", "mobile_phone": "999999999999"}, "enumeration": "false", "appoint_info": {"_token": "TMsAYroACMUYWVrxBepWc1zVDBwZuM9Moc3740Zc", "any_day": "on", "any_time": "on", "location_dropdown": "norwood_hall"}} ◀"
+"user_id": "a3f81160-81fa-11eb-bc69-273474788a80"
@ilhamzacky That is the dump of some sort of data.
Try writing the actual query you would expect to be written
Like
$appointments->whereIn('ssss', ['appoint_info'. 'location_dropdown'])>get();
@Sinnbeck 'ssss' is not a column
@ilhamzacky Then show what is :) How should the query look?
@Sinnbeck preference->appoint_info->location_dropdown - this is the column name , i need to explode the column and == to a string
Btw. Is supposed to be a lookup on a json column?
@Sinnbeck sorry i didnt get you
@ilhamzacky Is the preference column a json column?
https://laravel.com/docs/8.x/queries#json-where-clauses
And why are you trying to make the column into an array? You just want to query that single column right?
@Sinnbeck yes its a json column, it comes with a long text , i need to get only the name before a ',', and add a where close to filter
@ilhamzacky so it's an array in that column? Not an object. Don't think you can search that.
Can you show an example of the data in a row?
You should consider moving the data to a seperate table to make it easier to work with. If you store an array you should only use it for getting the whole thing
@Sinnbeck You should consider moving the data to a seperate table to make it easier to work with. - actually it was an old implementation , there were several records already been stored,
+"id": "a3f81160-81fa-11eb-bc69-273474788a80"
+"preference": "{"userinfo": {"dob_": {"day": "01", "year": "1992", "month": "02"}, "email": "[email protected]", "fname": "j", "lname": "j", "mname": "j", "_token": "TMsAYroACMUYWVrxBepWc1zVDBwZuM9Moc3740Zc", "action": "participant", "gender": "Male", "postcode": "m", "ethnicity": "Indian", "street_no": "m", "home_phone": "999999999999", "postal_code": "j", "street_name": "m"}, "enumeration": "false", "appoint_info": {"_token": "TMsAYroACMUYWVrxBepWc1zVDBwZuM9Moc3740Zc", "any_day": "on", "any_time": "on", "location_dropdown": "norwood_hall"}} ◀"
@ilhamzacky can you show an example of the data?
@Sinnbeck data means , i didn't get it , sorry ?
@ilhamzacky so this part is the json column ? Sorry it is hard to read. Maybe just copy/paste from your database manager
"preference": "{"userinfo": {"dob_": {"day": "01", "year": "1992", "month": "02"}, "email": "[email protected]", "fname": "j", "lname": "j", "mname": "j", "_token": "TMsAYroACMUYWVrxBepWc1zVDBwZuM9Moc3740Zc", "action": "participant", "gender": "Male", "postcode": "m", "ethnicity": "Indian", "street_no": "m", "home_phone": "999999999999", "postal_code": "j", "street_name": "m"}, "enumeration": "false", "appoint_info": {"_token": "TMsAYroACMUYWVrxBepWc1zVDBwZuM9Moc3740Zc", "any_day": "on", "any_time": "on", "location_dropdown": "norwood_hall
@Sinnbeck yes , on the location drop down , it comes with a long text like -norwood_hall, xxxx xxxxx xxxxx xxxx so i wont to explode and get only the norwood hall and add a where closure to filter it
@ilhamzacky so maybe something like this? Unless location_dropdown is an array, then try the third
($appointments->where('preference->appoint_info->location_dropdown', 'LIKE' '%ssss%')->get());
//or
($appointments->whereIn('preference->appoint_info->location_dropdown', ['ssss'])->get());
//or
$appointments->whereJsonContains('preference->appoint_info->location_dropdown ', 'ssss') ->get();
@Sinnbeck thanks , will check this out, thanks for your time too.... thank you very much
@ilhamzacky personally, if I had to make it searchable I would look into migration all the data to seperate tables
Please or to participate in this conversation.