doubi1713 2015-05-01 08:52
浏览 45

Laravel - 雄辩的物体和阵列夹头

Looking to use eloquent with array chunk but hitting errors that the first parameter needs to be array.

This is how I am doing things:

public function index() {
    $externalAccounts = ExternalUserAccount::all();
    return View::make('user_creator.index', compact('externalAccounts'));
}

Then in my view:

@foreach (array_chunk($externalAccounts, 4) as $key => $externalAccount)
    <div class="form-group">
        {{ Form::label($externalAccount->name, $externalAccount->display_name) }}
        {{ Form::checkbox($externalAccount->name, $externalAccount->id) }}
    </div>
@endforeach

However, if I use to array in my controller:

$externalAccounts = ExternalUserAccount::all()->toArray();

Then I get 'trying to get property of non object etc' error.

How should I do this?

  • 写回答

2条回答 默认 最新

  • dongmeixian9665 2015-05-01 09:22
    关注

    This is untested but looking at the Laravel documentation your best bet would be to use the Laravel Eloquent ORM to do it and remove the filtering in the view

    $externalAccounts = ExternalUserAccount::all()->take(4)->get();
    

    Laravel query builder

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大