Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在集合的每一行中插入一个新项目LARAVEL_Laravel_Eloquent - Fatal编程技术网

在集合的每一行中插入一个新项目LARAVEL

在集合的每一行中插入一个新项目LARAVEL,laravel,eloquent,Laravel,Eloquent,如何不使用循环和数组而使用集合来实现这一点 我有一个收集巫婆,我用这种方法创建的 $datas = collect($xml_datas['data']); 集合格式如下所示: [ { "reference": "3437247", "numero_mandat": "4536", "type_mandat": "simple", "operation": "vente", "type": "Bureau ", "adresse": "Bo

如何不使用循环和数组而使用集合来实现这一点

我有一个收集巫婆,我用这种方法创建的

  $datas = collect($xml_datas['data']);
集合格式如下所示:

[

{
    "reference": "3437247",
    "numero_mandat": "4536",
    "type_mandat": "simple",
    "operation": "vente",
    "type": "Bureau ",
    "adresse": "Boulevard du chine ",
    "code_postal": "34000",
    "ville": "MONTPELLIER",
    "prix": "400000",
    "honoraire_agence": "0",
    "honoraire_frais_dossier": "0",
    "pourcentage_honoraire_acquereur": "5.26",
    "taxe_fonciere": "0.000000",
    "charges_mensuelles": "0",
    "surf_habitable": "180",
    "depot_garantie": null,
    "nombre_piece": "9",
    "annee_construction": "1977",
    "loyer_mensuel_occupant": "0.00"
},
{
    "reference": "3437271",
    "numero_mandat": "6125",
    "type_mandat": "simple",
    "operation": "vente",
    "type": "Maison de caractère",
    "adresse": "5 rue de l'égalité",
    "code_postal": "34800",
    "ville": "PERET",
    "prix": "803000",
    "honoraire_agence": "0",
    "honoraire_frais_dossier": "0",
    "pourcentage_honoraire_acquereur": "0",
    "taxe_fonciere": "2000.000000",
    "charges_mensuelles": "0",
    "surf_habitable": "210",
    "depot_garantie": null,
    "nombre_piece": "7",
    "annee_construction": "2000",
    "loyer_mensuel_occupant": "0.00"
},
我想在集合的每一行添加3个新项目(这些值是相同的),因为这个集合有350个不同房地产项目,我想在所有这350个项目中添加这些数据

       'software' => 'adaptimmo',
       'user_id' =>Auth::user()->id,
       'slug_import' => 'SomeRandom',
这样我的收藏就这样结束了

[

{
    "software": "adaptimmo", // <--- We added
    "user_id": "1",
    "slug_import": "SomeRandom",
    "reference": "3437247",
    "numero_mandat": "4536",
    "type_mandat": "simple",
    "operation": "vente",
    "type": "Bureau ",
    "adresse": "Boulevard du chine ",
    "code_postal": "34000",
    "ville": "MONTPELLIER",
    "prix": "400000",
    "honoraire_agence": "0",
    "honoraire_frais_dossier": "0",
    "pourcentage_honoraire_acquereur": "5.26",
    "taxe_fonciere": "0.000000",
    "charges_mensuelles": "0",
    "surf_habitable": "180",
    "depot_garantie": null,
    "nombre_piece": "9",
    "annee_construction": "1977",
    "loyer_mensuel_occupant": "0.00"
},
{
    "software": "adaptimmo",
    "user_id": "1",
    "slug_import": "SomeRandom",
    "reference": "3437271",
    "numero_mandat": "6125",
    "type_mandat": "simple",
    "operation": "vente",
    "type": "Maison de caractère",
    "adresse": "5 rue de l'égalité",
    "code_postal": "34800",
    "ville": "PERET",
    "prix": "803000",
    "honoraire_agence": "0",
    "honoraire_frais_dossier": "0",
    "pourcentage_honoraire_acquereur": "0",
    "taxe_fonciere": "2000.000000",
    "charges_mensuelles": "0",
    "surf_habitable": "210",
    "depot_garantie": null,
    "nombre_piece": "7",
    "annee_construction": "2000",
    "loyer_mensuel_occupant": "0.00"
},
[
{

“软件”:“adaptimmo”,//在此处记录的集合中有许多可用的方法:

您可能正在寻找
each()
方法:

$items=collect($xml_datas['data'])->每个函数($item){
//向项目添加新键
$item->software='adaptimmo';
$item->user\u id=Auth::user()->id;
$item->slug_import='SomeRandom';
});

Okey刚才试过了,我想你是对的,但我现在有一个新问题,从我的理解来看,集合不会改变你给出的数据的“格式”,因此,由于我拥有的数据是数组,我不能使用->每个$item->软件,我有一个错误,即我不是一个对象。我如何解决这个问题呢?使用数组语法我n它是一个数组:
$item['software']='adaptimmo'
等。