0

モーダルピックリストフォームを作りたいです。これが私のコントローラーです:

public function picklist(Request $request)
{
    $q = $request->q;
    $lists = Customer::where('name', 'like', "%$q%")
        ->orderBy('name')->paginate('5');
    return view('customer._customer_list')
        ->with('lists', $lists);

}

これは view _customer_list.blade.php です

    <tbody>
        @foreach ($lists as $key => $list)
            <tr>
                <td>
                    {{ $list->name }}
                </td>
                <td>
                    <button data-dismiss="modal" class="btn btn-warning btn-xs btn-choose" 
                        type="button" data-id="{{ $list->id }}" data-name="{{ $list->name }}">Pilih</button>
                </td>
            </tr>
        @endforeach
    </tbody>
</table>
{!! $lists->appends(Request::except('page'))->render() !!}

これが私のルートです

Route::get('/customer/list/', 'PurchasesController@picklist');

localhost/customer/list を開くと、うまくいきました

しかし、このような別のビューに渡そうとすると

@section('content-modal')   
@include('purchase.modal_picklist', [
    'name' => 'customer',
    'title' => 'Daftar Customer',
    'placeholder' => 'Cari customer berdasarkan nama',
])
@endsection

@section('content-js')
@include('customer._customer_list')
<script>
    CreatePicklist('customer', '/customer/list?');
</script>   
@endsection

このようなルートで Route::get('/customer/add', 'CustomerController@create');

エラーが発生しました:

未定義変数: リスト (表示: /srv/web/resources/views/customer/_customer_list.blade.php) (表示: /srv/web/resources/views/customer/_customer_list.blade.php)

4

1 に答える 1

0

未定義変数: リスト (表示: /srv/web/resources/views/customer/_customer_list.blade.php) (表示: /srv/web/resources/views/customer/_customer_list.blade.php)

このエラーは、ビュー (foreach ループ内) でブレードがリスト変数を取得できないことを意味します。

以下のように、2 番目の引数としてパラメーターを指定してレンダー ビューを試してください。

public function picklist(Request $request)
{
    $q = $request->q;
    $lists = Customer::where('name', 'like', "%$q%")
        ->orderBy('name')->paginate('5');
    return view('customer._customer_list', ['lists' => $lists]);
}

これがうまくいくことを願っています:)

于 2016-11-18T08:51:40.970 に答える