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 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug