Laravel 4将结构化数组推送到模型集合

时间:2017-08-08 14:59:51

标签: laravel collections laravel-4 eloquent models

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

            using (Microsoft.Reporting.WebForms.LocalReport report = new LocalReport())
            {
                string appPath = AppDomain.CurrentDomain.BaseDirectory;

                report.ReportPath = System.IO.Path.Combine(appPath, "Reports", RDLName.ToString());

                foreach (KeyValuePair<string, object> dataSource in ReportDataSource)
                {
                    report.DataSources.Add(new ReportDataSource(dataSource.Key, dataSource.Value));
                }

                if (ReportParameters != null)
                {
                    foreach (KeyValuePair<string, object> parameter in ReportParameters)
                    {
                        report.SetParameters(new ReportParameter(parameter.Key, (parameter.Value == null ? null : parameter.Value.ToString())));
                    }
                }

                result = report.Render(Format);

                report.Dispose();


                return result;
            }

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

请提出任何建议,我完全被浪费了。

1 个答案:

答案 0 :(得分:0)

您可以使用新的用户实例执行此操作:

$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);