How can I convert collection laravel to array? - arrays

My code like this :
$test = $this->vendorRepository->getVendor($request->get('q'));
If I dd($test), the result is collection like this :
I want to convert it to array
I try like this :
dd($test->toArray());
The result like this :
value of id changed to 0
Why did it happen? How can I solve this problem?

This might be because your ID field is a string but laravel is expecting it to be an auto-incrementing integer.
Try adding this to the top of your model:
public $incrementing = false;

Related

convert string array to float MEL

I having a trouble with a code in MAYA 2020.
I want to create a new expression into a default value of a Arnold aiUserDataInt
I need the default value of a aiUserDataInt = attribute from a geometry that I crate name "ID"
so, my code looks like this:
string $Selected[] = `ls -selection`;
for ($node in $Selected)
aiUserDataInt1.default = $Selected.id;
but I have these error:
// Error: Line 2.37: Cannot cast data of type string[] to float. //
So, I suppose default value do not accept arrays
my question would be: is there a way to convert array into float?
or what am I doing wrong?
Thanks in advance
Unfortunately that's not how mel works. You can do:
string $Selected[] = `ls -selection`;
for ($node in $Selected)
{
int $id = getAttr($node + ".id");
setAttr("aiUserDataInt1.default", $id);
}
Didn't test it, but it should work like this. You get and set attributes with getAttr() and setAttr().

How to update values in a nested json file by Powershell

I want to update some values of below content which i believe a json file. This is the output of azure devops release definition and I need to reuse the content modifying some fields.
I can simply update values like id and name using these lines
$ReleaseDef.Name = $newReleaseName
$ReleaseDef.path = $folderQA
But I dont know how to update array fields like artifact and triggers. I can get values by calling $ReleaseDef.artifacts.sourceid
but can not set any values there , It throws errors like The property 'sourceid' cannot be found on this object. Verify that the
property exists and can be set.
Please suggest
source : userInterface
revision : 4
description :
createdBy : #{displayName=Jyotiprakash Nayak; url=https://azuredevopsdv
.ril.com/EntApps/_apis/Identities/2ca8bd5d-7797-4177-b7bb-2
6daa0d29ed9; _links=;
id=2ca8bd5d-7797-4177-b7bb-26daa0d29ed9;
uniqueName=domain\Jyotiprakash.Nayak; imageUrl=https://azuredev
opsdv.company.com/EntApps/_apis/GraphProfile/MemberAvatars/win.
Uy0xLTUtMjEtMjIwNzU5NTE2Ni03MjEyNTY2NjUtNTU2MTkwNDkyLTQ4NjY
yMw; descriptor=win.Uy0xLTUtMjEtMjIwNzU5NTE2Ni03MjEyNTY2NjU
tNTU2MTkwNDkyLTQ4NjYyMw}
createdOn : 2019-12-10T09:11:11.057Z
modifiedBy : #{displayName=Jyotiprakash Nayak; url=https://azuredevopsdv
.company.com/EntApps/_apis/Identities/2ca8bd5d-7797-4177-b7bb-2
6daa0d29ed9; _links=;
id=2ca8bd5d-7797-4177-b7bb-26daa0d29ed9;
uniqueName=Domain\Jyotiprakash.Nayak; imageUrl=https://azuredev
opsdv.comapny.com/EntApps/_apis/GraphProfile/MemberAvatars/win.
Uy0xLTUtMjEtMjIwNzU5NTE2Ni03MjEyNTY2NjUtNTU2MTkwNDkyLTQ4NjY
yMw; descriptor=win.Uy0xLTUtMjEtMjIwNzU5NTE2Ni03MjEyNTY2NjU
tNTU2MTkwNDkyLTQ4NjYyMw}
modifiedOn : 2019-12-13T09:16:13.463Z
isDeleted : False
variables :
variableGroups : {}
environments : {#{id=7; name=Stage 1; rank=1; owner=; variables=;
variableGroups=System.Object[]; preDeployApprovals=;
deployStep=; postDeployApprovals=;
deployPhases=System.Object[]; environmentOptions=;
demands=System.Object[]; conditions=System.Object[];
executionPolicy=; schedules=System.Object[];
currentRelease=; retentionPolicy=; processParameters=;
properties=; preDeploymentGates=; postDeploymentGates=;
environmentTriggers=System.Object[]; badgeUrl=https://azure
devopsdv.comapny.com/EntApps/_apis/public/Release/badge/e0b1a36
0-01a5-4eea-af57-b2a461559ac9/7/7}}
artifacts : {#{sourceId=e0b1a360-01a5-4eea-af57-b2a461559ac9:48;
type=Build; alias=_eCAM-Team-CI; definitionReference=;
isPrimary=True; isRetained=False}}
triggers : {#{artifactAlias=_eCAM-Team-CI;
triggerConditions=System.Object[];
triggerType=artifactSource}}
releaseNameFormat : Release-$(rev:r)
tags : {}
pipelineProcess : #{type=designer}
properties : #{DefinitionCreationSource=}
id : 7
name : Release-Template-1
path : \QA
projectReference :
url : https://azuredevopsdv.company.com/EntApps/e0b1a360-01a5-4eea-af
57-b2a461559ac9/_apis/Release/definitions/7
_links : #{self=; web=}
These attributes contain hash table values.
You should be able to update by specifying the key and its new value like so:
$ReleaseDef.artifacts["sourceid"] = "someValueHere"
Thanks all for your valuable helps, I finally made it work through some foreach loops.
```$artifact = $json.artifacts
foreach ($value in $artifact)
{
$value.alias = "_$newReleaseName"
$value.sourceId = "$($projectid):$($BuildID)"
}
foreach ($triggervalue in $snapshot.triggers)
{
$triggervalue.artifactAlias = "_$newReleaseName"
}```

How to convert BasicDBList to List<T> using MappingMongoConverter (spring-data-mongo)?

Executing below code returns the result that contains the element of type hashmap instead of type T (the basicDBList coming from mongoDB does not have "_class" attribute:
com.mongodb.BasicDBList basicDBList = // output of mongoDB query;
List<T> result = mongoOperations.getConverter().read(List.class, basicDbList);
Is there any way to provide type information of List to the read method ?
Not exactly clear what you're trying to achieve, but if you acquired your BasicDBList by calling the getRawResults().get("result") of an AggregationResults instance, you can instead call getMappedResults:
Aggregation aggregation = Aggregation.newAggregation(...);
AggregationResults<Foo> r = mongoTemplate.aggregate(aggregation, "foos", Foo.class);
List<Foo> foos = r.getMappedResults();

Sorting an arraycollection with a numeric value coming from 2 diffrent fields

Hi guys I need to sort an arraycollection. the problem is that my array is combined from two diffrent arrays, in one the age field is called "AGE", and in the other the age is called "MYAGE".
Now I need to sort the combined array according to age but I got two fields with diffrent names. I can go through the array and change all "MYAGE" to "AGE" but i was wondering if theres maybe a way to sort the array in its current status?
Thanks ahead
Say you have an ArrayCollection called myCollection. I hope the following will solve your request for that:
private function compareItems(a:Object, b:Object, fields:Array = null):int
{
var firstValue:Number = "AGE" in a ? a["AGE"] : a["MYAGE"];
var secondValue:Number = "AGE" in b ? b["AGE"] : b["MYAGE"];
if (firstValue == secondValue)
return 0;
return firstValue > secondValue ? 1 : -1;
}
…
var sort:ISort = new Sort();
sort.compareFunction = compareItems;
myCollection.sort = sort;
myCollection.refresh();

How to query SOLR for empty fields?

I have a large solr index, and I have noticed some fields are not updated correctly (the index is dynamic).
This has resulted in some fields having an empty "id" field.
I have tried these queries, but they didn't work:
id:''
id:NULL
id:null
id:""
id:
id:['' TO *]
Is there a way to query empty fields?
Thanks
Try this:
?q=-id:["" TO *]
One caveat! If you want to compose this via OR or AND you cannot use it in this form:
-myfield:*
but you must use
(*:* NOT myfield:*)
This form is perfectly composable. Apparently SOLR will expand the first form to the second, but only when it is a top node. Hope this saves you some time!
According to SolrQuerySyntax, you can use q=-id:[* TO *].
If you have a large index, you should use a default value
<field ... default="EMPTY" />
and then query for this default value.
This is much more efficient than q=-id:["" TO *]
You can also use it like this.
fq=!id:['' TO *]
If you are using SolrSharp, it does not support negative queries.
You need to change QueryParameter.cs (Create a new parameter)
private bool _negativeQuery = false;
public QueryParameter(string field, string value, ParameterJoin parameterJoin = ParameterJoin.AND, bool negativeQuery = false)
{
this._field = field;
this._value = value.Trim();
this._parameterJoin = parameterJoin;
this._negativeQuery = negativeQuery;
}
public bool NegativeQuery
{
get { return _negativeQuery; }
set { _negativeQuery = value; }
}
And in QueryParameterCollection.cs class, the ToString() override, looks if the Negative parameter is true
arQ[x] = (qp.NegativeQuery ? "-(" : "(") + qp.ToString() + ")" + (qp.Boost != 1 ? "^" + qp.Boost.ToString() : "");
When you call the parameter creator, if it's a negative value. Simple change the propertie
List<QueryParameter> QueryParameters = new List<QueryParameter>();
QueryParameters.Add(new QueryParameter("PartnerList", "[* TO *]", ParameterJoin.AND, true));
you can do it with filter query
q=*:*&fq=-id:*
A note added here, to make the field searchable first, it needs the field type in SOLR schema set to "indexed = true". Then you can use "field_name:*" for string type and "field_name:[* TO *]" for numeric type.

Resources