I suggest you rethink your strategy, there is almost never a good idea or a valid reason for storing data that you search, or update as json. I suggest you read this post https://tray2.se/posts/database-design
Jun 24, 2022
5
Level 1
Selected multiple items and saved with json encode aren't displayed as selected in edit, bootstrap selectpicker plugin
Im having an issue with making items selected in a multiple select box with selectpicker javascript plugin appear as selected in the edit page. I am saving the picks as json and have no issue with saving them, but when Im editing the entry all the picks aren't selected and the field is blank.
I tried the following in my edit blade:
<div class="mb-3 col-md-6">
<label for="">Quotation Description:</label>
<script>
$(function () {
$('select').selectpicker();
});
</script>
<select class="selectpicker form-control" name="joinery_name[]" multiple required>
@php
$joinery_name = json_decode($quot_edit->joinery_name)
@endphp
@foreach($joinery as $joineries)
<option value="{{ $joineries->name }}" {{ $quot_edit->joindery_name == $joineries->name ? 'selected':'' }} name="joinery_name[]">{{ $joineries->name }}</option>
@endforeach
</select>
</div>
My quot model is
protected $table = 'client_quotation';
protected $primaryKey = 'quotId';
protected $fillable = [
'name',
'email',
'phone_number',
'contact_person',
'date_of_sending_inquiry',
'joinery_name',
'verification_date',
'notes',
'verified_receipt',
'created_by',
'holding_id'
];
public function followup()
{
return $this->hasMany(QuotationFollowup::class, 'client_quotation_id');
}
my joinery model is
protected $table = 'joinery';
protected $fillable = [
'name',
'created_by'
];
}
What can I change in my edit blade to make the selected values decoded from json appear as selected in the multiple select with selectpicker plugin?
Level 73
2 likes
Please or to participate in this conversation.