【发布时间】:2019-04-02 01:12:21
【问题描述】:
我想使用 Laravel Collective Select 和 Select2 从控制器中使用以下代码检索数据:
public function create() {
$customers=Customer::all();
$customerAlt= Customer::get()->pluck('customer_name', 'id')->prepend('Please Select', '');
return view('req.create', compact 'customer', 'customerAlt')
}
现在在我的刀片视图中,如果使用普通形式,我想使用类似这样的 Laravel 集合
<select id="NamaPelanggan" name="nama_pelanggan" class="form-control">
<option>Pilih Satu</option>
@foreach($customers as $cus)
<option data-contact="{{ $cus->contact_person }}" data-phone="{{ $cus->phone_number }}" value="{{$cus->id}}">{{$cus->name}}</option>
@endforeach
</select>
并且下面的JS来填充其他文本字段PIC和PIC_Phone
$('#NamaPelanggan').change(function() {
let contact = $(this).find(':selected').data('contact_person');
let phone = $(this).find(':selected').data('phone_number');
$('#PIC').val(contact);
$('#PIC_Phone').val(phone);
})
问题是我如何使用 laravelcollective 和 select2 来替换上面的正常选择以及我应该使用哪个 $customer
【问题讨论】:
标签: javascript php laravel jquery-select2 laravelcollective