I want to retrieve data using Laravel Collective Select with Select2 from a controller using this code:
public function create() {
$customers=Customer::all();
$customerAlt= Customer::get()->pluck('customer_name', 'id')->prepend('Please Select', '');
return view('req.create', compact 'customer', 'customerAlt')
}
now on my blade view, I want to use Laravel collective something like this if using a normal form
<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>
And The JS is below to fill other text field PIC and 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);
})
The Question is how I use laravelcollective with select2 to replace the normal select above and which $customer
that I should use