【问题标题】:Laravel 4 pushing structurized array to model collectionLaravel 4 将结构化数组推送到模型集合
【发布时间】:2018-01-16 05:29:38
【问题描述】:

我有模型用户和具有相同字段的新自定义集合。

$users = User::all();

$object = new \Illuminate\Database\Eloquent\Collection;
$object->add(
    [
        "name"=>'John',
        "status"=>"pending",
        "created_at"=> "-0001-11-30 00:00:00",
        "updated_at"=> "-0001-11-30 00:00:00",
    ]
);

// Trying to pull new to the main;
$users->push($object);

一切都很好,但是当我尝试循环新集合时,它不会检索推送的数据,并抛出 Undefined Propery

任何建议,拜托,我完全浪费了。

【问题讨论】:

  • btw:你知道 laravel 4 正在腐烂吗?最后一次发布是 2014 年 6 月 1 日

标签: laravel collections laravel-4 eloquent models


【解决方案1】:

您可以像这样使用新的用户实例来做到这一点:

$users = User::all();

$newUser = new User([
        "name"=>'John',
        "status"=>"pending",
        "created_at"=> "-0001-11-30 00:00:00",
        "updated_at"=> "-0001-11-30 00:00:00",
    ]);

// Trying to pull new to the main;
$users->push($newUser);

【讨论】:

    猜你喜欢
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    • 2016-03-23
    • 2017-07-10
    • 2022-06-10
    • 2021-10-08
    • 1970-01-01
    相关资源
    最近更新 更多