Eloquent Order By alphabetically doesn't work - laravel

Here is a very simple line of code I am running:
return User::orderBy('first_name', 'asc')->get();
I expect to get the returned result in alphabetical order. Here is what I get:
{
"id": "1",
"first_name": "Kousha",
...
},
{
"id": "10",
"first_name": "Monica",
...
},
{
"id": "9",
"first_name": "Alex",
...
},
{
"id": "2",
"first_name": "Ali",
...
},
{
"id": "7",
"first_name": "Chris",
...
},
{
"id": "5",
"first_name": "Amin",
...
},
{
"id": "6",
"first_name": "Felix",
...
},
{
"id": "8",
"first_name": "Aleksi",
...
},
{
"id": "3",
"first_name": "Ryan",
...
},
{
"id": "4",
"first_name": "Paul",
...
}
If I try the order in descending order, I get another gibberish result. The only thing the order works for is the id. What am I missing here?

Related

Can I delete one item in JSON by jsonpath use golang

I have a json like this:
{
"firstName": "John",
"lastName": "doe",
"age": 26,
"address": {
"streetAddress": "naist street",
"city": "Nara",
"postalCode": "630-0192"
},
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4567-8888"
},
{
"type": "home",
"number": "0123-4567-8910"
}
]
}
And get a json path expression: $.phoneNumbers.*.type
How can I delete the keys by this expression in Go?

Extract the id by validating the child element from the JSON response

For the following response as a form of JSON, I want to extract a particular value on the validating first name.
{
"system": false,
"redirect": false,
"url": "user",
"infinite": false,
"csrf": {
"name": "csrf_token",
"value": "1fc51ba92c87ad1f086195e36a4a6b02"
},
"version": "2.0.1869",
"view": {
"data": {
"items": [
{
"id": null,
"name": "No Workspace",
"users": [
{
"id": "170303",
"account_id": "143003",
"email": "Perfuser554#gmail.com",
"first_name": "Perf-WxC",
"last_name": "Eve-971"
},
{
"id": "170318",
"account_id": "143003",
"user_type_id": "3",
"email": "Perfuser555#gmail.com",
"password_format": "1",
"first_name": "Perf-WMV",
"last_name": "Eve-972"
},
{
"id": "170320",
"account_id": "143003",
"email": "Perfuser556#gmail.com",
"first_name": "Perf-YTC",
"last_name": "Eve-973"
},
{
"id": "170321",
"account_id": "143003",
"email": "Perfuser557#gmail.com",
"first_name": "Perf-ZvF",
"last_name": "Eve-974"
},
{
"id": "170322",
"account_id": "143003",
"email": "Perfuser558#gmail.com",
"first_name": "Perf-WmO",
"last_name": "Eve-975"
}
],
"company_name": "Local host"
}
]
},
"show_nav": true
}
}
I want to extract the id and account_id for a particular user on the basis of first name. For example for Perf-YTC the id is 170320 and account_id is 143003.
Could use the JSON extractor, but dont know the index value mentioned in the image.
You could use the following as a JSON extractor,
$..[?(#.first_name == "Perf-YTC")].id for id and
$..[?(#.first_name == "Perf-YTC")].account_id for account_id

Vuetify's v-select doesn't show all the items for some reason

This is extremely weird for me - my code is very basic:
<v-select
chips
multiple
:items="areas"
v-model="person.applicant.areas"
:label="trans('Areas of interest')"
item-text="name"
item-value="id"
></v-select>
The items when echoed right before that with {{areas}} returns as follows:
[
{ "interestsAreas": "TEst", "id": 0, "name": "TEst" },
{ "interestsAreas": "Test2", "id": 1, "name": "Test2" },
{ "interestsAreas": "Something", "id": 0, "name": "Something" },
{ "interestsAreas": "1", "id": 1, "name": "1" },
{ "interestsAreas": "2", "id": 2, "name": "2" },
{ "interestsAreas": "3", "id": 3, "name": "3" }
]
Yet, whatever I do the v-select drops "Something" and "1" out of the dropdown even if I rename them or whatever.
I can't catch the logic behind dropping some of them, is there any known bug or something that I am not doing right in the invocation?
I am guessing it has something to do with the item-value, as id needs to be unique
[
{ "interestsAreas": "TEst", "id": 0, "name": "TEst" },
{ "interestsAreas": "Test2", "id": 1, "name": "Test2" },
{ "interestsAreas": "Something", "id": 0, "name": "Something" },// the id value is already used so try changing it
{ "interestsAreas": "1", "id": 1, "name": "1" },//same for this one as well
{ "interestsAreas": "2", "id": 2, "name": "2" },
{ "interestsAreas": "3", "id": 3, "name": "3" }
]

Update property in array in RethinkDB

I have the following structure in RethinkDB
{ "id": "1", "values": [{ "id": 1, "firstname": "foo" }] },
{ "id": "2", "values": [{ "id": 2, "firstname": "bar" }] }
How can I update each "values" array and add an additional property to it?
For instance I'd like to achieve
{ "id": "1", "values": [{ "id": 1, "firstname": "foo", "lastname": null }] },
{ "id": "2", "values": [{ "id": 2, "firstname": "bar", "lastname": null }] }
Something like:
r.table('test').get(id).update(function(row) {
return {values: row('values').map(function(val)
return val.merge({lastname: null});
});
})

Get particular key's and value's from JSON array - Ruby [duplicate]

This question already has answers here:
Ruby: Easiest Way to Filter Hash Keys?
(14 answers)
Closed 6 years ago.
I am a beginner with Ruby, and I have the following Json array:
"elements": [
{
"type": "Contact",
"id": "1",
"createdAt": "131231235",
"name": "test",
"updatedAt": "1456328049",
"accountName": "Mr Test",
"country": "China",
"firstName": "Test",
"lastName": "lastNameTest",
},
{
"type": "Contact",
"id": "2",
"createdAt": "156453447",
"name": "test2",
"updatedAt": "124464554",
"accountName": "Mr Test2",
"country": "Germany",
"firstName": "Test2",
"lastName": "lastNameTest2",
},...
]
I want to filter out only a few keys + values: for example I want to return only the id,name,accountName,firstname and lastname.
So the exspected output is the following:
"elements": [
{
"id": "1",
"name": "test",
"accountName": "Mr Test",
"firstName": "Test",
"lastName": "lastNameTest",
},
{
"id": "2",
"name": "test2",
"accountName": "Mr Test2",
"firstName": "Test2",
"lastName": "lastNameTest2",
},...
]
I tried the following: create a filter array which has the elements I want to return and then map over the items but then I get stuck..
filters = []
filters.push("accountName")
filters.push("lastName")
filters.push("firstName")
filters.push("Id")
output["elements"].each do |item|
result = []
item.map {|key,value|filters.include? key}
result.push(?)
Thank you for the help.
Check this out, you should be able to work out from this:
output = { "elements": [
{
"id": "1",
"name": "test",
"accountName": "Mr Test",
"firstName": "Test",
"lastName": "lastNameTest",
"somethoong": "sdsad"
},
{
"id": "2",
"name": "test2",
"accountName": "Mr Test2",
"firstName": "Test2",
"lastName": "lastNameTest2"
}
]}
attribs = %w(accountName lastName firstName id)
output[:elements].each do |item|
item.delete_if{|k,v| !attribs.include?(k.to_s)}
end

Resources