Laravel模型数据foreach

时间:2017-04-25 12:44:46

标签: php laravel foreach

我有以下行$totalRequests = \App\LoanRequest::all();,它返回与Applicant One to ManyLoanRequest关系的模型$totalRequests[0]->applicant->region

因此我可以foreach()使用regions访问申请人数据。

问题:

现在,我想要Applicant模型中的applicants或表LoanRequest::all()中的所有不同 regions,并希望推送$totalRequests = \App\LoanRequest::all(); foreach($totalRequests as $applicant){ $filterMeta = []; array_push($applicant->aplicant->region, $filterMeta); } 1}}到一个数组然后我可以传递给视图。

我在尝试什么:

Indirect modification of overloaded property App\Applicant::$region has no effect

它抛出:

public static final String SQL_CREATE_SENS = "create table " + TABLE_NAME_SENS + " (" + KEY + " integer primary key autoincrement," + TIMESTAMP + " text not null," // SQL -> String + MESSWERT_Temp + " real not null," + MESSWERT_DRUCK + " real not null," + MESSWERT_FEUCHTE + " real not null" + ")";

1 个答案:

答案 0 :(得分:0)

如果要将区域推送到数组,则使用错误的参数顺序。另外,你不应该在循环之外初始化过滤器元数组吗?

{{1}}