未定义属性:Illuminate \ Pagination \ LengthAwarePaginator :: $ hasDepartment

时间:2017-12-06 09:36:06

标签: php laravel-5

这是我的控制器。

public function index()
{
    $customers = $this->customerType->whereNull('deleted_at')->paginate(10);
    // please write the view code
    return view('admin.customer_type.index')->with(['customers' => $customers]);
}

告诉我刀片file.someone中的错误请解决,谢谢

<fieldset>
    <label for="visible">Department</label><br>
    <input name="hasDepartment" type="radio" value="ture" {!! $customers->hasDepartment == 'ture' ? 'checked' : '' !!}> True<br>
    <input name="hasDepartment" type="radio" value="false" {!! $customers->hasDepartment == 'false' ? 'checked' : '' !!}> False
</fieldset>

1 个答案:

答案 0 :(得分:0)

$customers实际上是一个paginator实例,你需要在它上面使用每个$customer,如下所示:

@foreach ($customers as $customer)
    <fieldset>
        <label for="visible">Department</label><br>
        <input name="hasDepartment" type="radio" value="ture" {!! $customer->hasDepartment == 'ture' ? 'checked' : '' !!}> True<br>
        <input name="hasDepartment" type="radio" value="false" {!! $customer->hasDepartment == 'false' ? 'checked' : '' !!}> False
    </fieldset>
@endforeach