When I am using get api and get the data in json format
{
"uuid": "46d00217-6e35-485c-ac20-c204a8a24a68",
"name": "AMan",
"dispute_location": "Hyder",
"max_dispute_value": "200",
"min_dispute_value": "100",
"state": "U.p",
"district": "morene",
"calendar_id": "3",
"description": null,
"subject_matters": [
{
"id": 1,
"name": "A",
"created_at": "2020-08-14T12:24:52.000000Z",
"updated_at": "2020-08-14T12:24:52.000000Z",
"pivot": {
"court_uuid": "46d00217-6e35-485c-ac20-c204a8a24a68",
"subject_matter_id": 1
}
},
{
"id": 2,
"name": "B",
"created_at": "2020-08-14T12:24:57.000000Z",
"updated_at": "2020-08-14T12:24:57.000000Z",
"pivot": {
"court_uuid": "46d00217-6e35-485c-ac20-c204a8a24a68",
"subject_matter_id": 2
}
}
]
}
but i want subject_matters data in this format
"subject_matters": [1,2]
Api resource (court resources)
You can use ->pluck('id'); in your resource.
return [
'subject_matters_id' => $this->subjectMatters->pluck('id')
]
It should return an array of subject matter IDs.
Related
I've a little problem, fetch query over react to Graphql work.
But when I ask a complex query, I receive this answer :
How I can read all variable but not the variable in the "operation":
Name
ID
How I can read this 2 Variables ?
[
{
"__typename": "Journal",
"id": "1",
"name": "Journal1",
"state": "ACTIVE",
"operation": {
"__typename": "Operation",
"id": "1",
"name": "Oper1OnlyName"
}
},
{
"__typename": "Journal",
"id": "2",
"name": "Default",
"state": "ACTIVE",
"operation": {
"__typename": "Operation",
"id": "15",
"name": "Oper15ID"
}
},
{
"__typename": "Journal",
"id": "3",
"name": "Nachrichten",
"state": "ACTIVE",
"operation": {
"__typename": "Operation",
"id": "15",
"name": "Oper15ID"
}
},
{
"__typename": "Journal",
"id": "4",
"name": "WEMA",
"state": "ACTIVE",
"operation": null
},
I wrote this code to get the product information with it's images and category:
->where('category_id', 5)
->with('category', 'Files')->get();
my result is:
{
"id": 2,
"name": "test",
"price": 13000,
"description": "some text ...",
"shop_id": 1,
"rate": 0,
"category_id": 5,
"discount_percent": 20,
"category": {
"id": 5,
"name": "cat1",
"shop_id": 1
},
"files": [
{
"id": 99,
"disk_name": "5ef1af07d6d98778754621.jpg",
"file_name": "13330983_xl.jpg",
"file_size": 69813,
"content_type": "image/jpeg",
"title": null,
"description": null,
"field": "product_gallery",
"sort_order": 99,
"created_at": "2020-06-23 07:28:07",
"updated_at": "2020-06-23 07:28:10",
"path":...... storage/app/uploads/public/5ef/1af/07d/5ef1af07d6d98778754621.jpg",
"extension": "jpg"
}
]
}
now i want to access the path field, how can i do it?
i use this way for access but i don't get result:
products[0].files[0].path
You should use toArray() function to convert data likes this
->where('category_id', 5)
->with('category', 'Files')->get()->toArray();
And then access
products[0]['files'][0]['path']
I´m importing a JSON-Datasource in Denodo which contains 2 arrays. In order to work with the data i flatten those arrays. However when delivering the data I want to get back to the initial array structure to get something like
{
"name": "name_of_my_view",
"elements": [
{
"result": [
{
"id": 40033495,
"first_name": Max,
"last_name": Mustermann
},
{
"id": 39960791,
"first_name": "Markus",
"last_name": "Markwart"
}
],
"took_ms": 4,
"result_count": 323,
"errors": [
{}
]
}
],
"links": [
{
"rel": "self",
"href": "https://address"
}
]
}
I have flattend both arrays (result, errors) in order to edit the respective fealds within them. However i only see the option of using UNION to combine them. If i do so I end up having all fealds in one hierarchy like (Ignore the sorting in this example) Oh and note that "code" and "description" are within the "error" array and are not shown in the above example because there are no errors in it:
{
"name": "name_of_my_view",
"elements": [
{
"took_ms": 4,
"result_count": 323,
"code": null,
"description": null,
"id": null,
"first_name": null,
"last_name": null
},
{
"took_ms": 4,
"result_count": 323,
"code": null,
"description": null,
"id": 40033495,
"first_name": null,
"last_name": null
}
],
"links": [
{
"rel": "self",
"href": "https://address"
}
]
}
I have an array as the source. I want to transform source into result by using Groovy.
I don't see any similar question. That's why I post here.
I tried to get the first member in the family and put all other members into a subList with this code but it failed
source.each{ family -> family.each{
member -> member.get(0).collate(1,family.size()-1)
}
}
source:
[
[{
"id": "0001",
"role": "parent",
"age": 30
},
{
"id": "0002",
"role": "child",
"age": 1
},
{
"id": "0003",
"role": "child",
"age": 3
}
],
[{
"id": "0004",
"role": "parent",
"age": 31
},
{
"id": "0005",
"role": "child",
"age": 5
}
]
]
result:
[{
"id": "0001",
"role": "parent",
"age": 30,
"children": [{
"id": "0002",
"role": "child",
"age": 1
},
{
"id": "0003",
"role": "child",
"age": 3
}
]
},
{
"id": "0004",
"role": "parent",
"age": 31,
"children": [{
"id": "0005",
"role": "child",
"age": 5
}]
}]
You can shape the data by adding the "parent" map with a new map only containing the children (+ in groovy does that merge). E.g.:
def data = new groovy.json.JsonSlurper().parseText('[[{ "id": "0001", "role": "parent", "age": 30 }, { "id": "0002", "role": "child", "age": 1 }, { "id": "0003", "role": "child", "age": 3 } ], [{ "id": "0004", "role": "parent", "age": 31 }, { "id": "0005", "role": "child", "age": 5 }]]')
println(data.collect{ groups ->
// XXX
groups.find{ it.role=="parent" } + [children: groups.findAll{it.role=="child"}]
})
// => [[id:0001, role:parent, age:30, children:[[id:0002, role:child, age:1], [id:0003, role:child, age:3]]], [id:0004, role:parent, age:31, children:[[id:0005, role:child, age:5]]]]
I'm having the hardest time figuring out how to display the following JSON file in my Angularjs repeat.
for the following JSON results, I thought I could simply display the title in an ng-repeat with the following:
<div ng-repeat="x in results">
{{x.data[0].title}}
</div>
But I'm not seeing results.
Here is the JSON:
{
"data": [
{
"id": 1,
"title": "Temp Title",
"description": "Temp Description",
"created_at": {
"date": "2016-03-15 07:10:17.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2016-03-15 07:10:17.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"user": {
"data": {
"id": 29,
"displayName": "chris.nakea",
"email": "chris.nakea#freshconsulting.com",
"join_date": 1458025279,
"profile": {
"data": {
"id": 29,
"displayName": "chris.nakea",
"avatar": null,
"firstName": null,
"lastName": null,
"bio": null,
"city": null,
"zipcode": null,
"state": null,
"country": null,
"latitude": null,
"longitude": null,
"avatars": {
"data": [
{
"id": "default_avatar.png",
"filename": "default_avatar.png",
"url": "https://cdn.band.dev/common/images/common/default_avatar.png",
"created_at": {
"date": "2016-03-15 00:00:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"images": {
"small": "https://cdn.band.dev/common/images/common/default_avatar_small.png",
"medium": "https://cdn.band.dev/common/images/common/default_avatar_medium.png",
"large": "https://cdn.band.dev/common/images/common/default_avatar_large.png"
}
}
]
},
"coverPhotos": {
"data": []
}
}
}
}
},
"category": {
"data": {
"id": 2,
"name": "Staff / Events",
"description": "Staff / Events",
"colorCode": "#242156",
"iconName": "icon-staff-events",
"iconCharacterCode": "c108"
}
},
"attachments": {
"data": [
{
"id": "1d3f96e2286c27ee599c9e49a0c33da0",
"filename": "man.jpg",
"url": "https://api.band.dev/v1/file/1d3f96e2286c27ee599c9e49a0c33da0",
"created_at": {
"date": "2016-03-15 07:10:17.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"images": {
"small": "https://api.band.dev/v1/file/50af58b3d52d8629e9f5c4d0dcdd5181",
"medium": "https://api.band.dev/v1/file/51535d38f7b3cd82313eac2414059d83",
"large": "https://api.band.dev/v1/file/a7be1dada18e4041cf48aea377cafa29"
}
}
]
}
},
{
"id": 2,
"title": "Temp Title",
"description": "Temp Description",
"created_at": {
"date": "2016-03-15 07:12:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2016-03-15 07:12:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"user": {
"data": {
"id": 29,
"displayName": "chris.nakea",
"email": "chris.nakea#freshconsulting.com",
"join_date": 1458025279,
"profile": {
"data": {
"id": 29,
"displayName": "chris.nakea",
"avatar": null,
"firstName": null,
"lastName": null,
"bio": null,
"city": null,
"zipcode": null,
"state": null,
"country": null,
"latitude": null,
"longitude": null,
"avatars": {
"data": [
{
"id": "default_avatar.png",
"filename": "default_avatar.png",
"url": "https://cdn.band.dev/common/images/common/default_avatar.png",
"created_at": {
"date": "2016-03-15 00:00:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"images": {
"small": "https://cdn.band.dev/common/images/common/default_avatar_small.png",
"medium": "https://cdn.band.dev/common/images/common/default_avatar_medium.png",
"large": "https://cdn.band.dev/common/images/common/default_avatar_large.png"
}
}
]
},
"coverPhotos": {
"data": []
}
}
}
}
},
"category": {
"data": {
"id": 2,
"name": "Staff / Events",
"description": "Staff / Events",
"colorCode": "#242156",
"iconName": "icon-staff-events",
"iconCharacterCode": "c108"
}
},
"attachments": {
"data": [
{
"id": "a93cf8df7b60686e7ca6884d0ce353c8",
"filename": "man2.jpg",
"url": "https://api.band.dev/v1/file/a93cf8df7b60686e7ca6884d0ce353c8",
"created_at": {
"date": "2016-03-15 07:12:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"images": {
"small": "https://api.band.dev/v1/file/cd04551395a355f4792fb85833156741",
"medium": "https://api.band.dev/v1/file/4ff543cd8f5055bfecd703dedaee6d87",
"large": "https://api.band.dev/v1/file/5cdd9a0c3650228e0b93f9c6cd1404df"
}
}
]
}
}
]
}
You can just remove the datap[0] part and get the output
<div ng-repeat="x in results.data">
{{x.title}}
</div>
Output:
Temp Title
Temp Title
if you want to filter then you can do it by
<div ng-repeat="x in results.data | filter: { id: '1' }">
{{x.title}}
</div>
Output:
Temp Title
<div ng-repeat="item in data">{{item.title}}</div>
And in your controller, bind the json to the scope.
$scope.data = jsonData.data;
Here's a fiddle for you - jsFiddle
<div ng-repeat="x in results.data">
{{x.title}}
</div>
https://jsfiddle.net/nvqf8oo7/6/
Thank you all for responding. I finally figured out that the reason I wasn't seeing anything was because I am using ui.bootstrap's modal and I was out of scope.
I resolved this by moving the ng-repeat out of the modal, but I could have also tried to work with the modal scope itself.