我想制作一个模态选项列表。这是我的控制器:
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);
}
这是查看_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)
答案 0 :(得分:0)
未定义变量:列表(查看:/srv/web/resources/views/customer/_customer_list.blade.php)(查看:/srv/web/resources/views/customer/_customer_list.blade.php)
此错误表示在您的视图中(在foreach循环中)刀片无法获取列表变量。
尝试渲染视图,将参数作为第二个参数,如下面的
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]);
}
希望这适合你:)