Laravel 4 将结构化数组推送到模型集合
Laravel 4 pushing structurized array to model collection
我有模型用户和具有相同字段的新自定义集合。
$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);
一切都很好,但是当我尝试循环新集合时,它没有检索推送的数据,并抛出 未定义 属性.
任何建议,请,我完全浪费了。
您可以像这样使用新的用户实例来完成此操作:
$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);
我有模型用户和具有相同字段的新自定义集合。
$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);
一切都很好,但是当我尝试循环新集合时,它没有检索推送的数据,并抛出 未定义 属性.
任何建议,请,我完全浪费了。
您可以像这样使用新的用户实例来完成此操作:
$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);