I have this code for multiselect dropdown
<select id="kit" name="tool_id[]" multiple class="form-control single-select selectpicker">
<option value="">Select Tool Name</option>
<?php foreach($tools as $tool){?>
<option value="<?php echo $tool->id;?>"><?php echo $tool->name;?></option>
<?php }?>
</select>
I can insert data in database ,but unable to retrieve on show blade
value stores in database like this in array
Help me to retrieve array value from MySql DB
Retrieve array value from data base in laravel
3
Answers
Since you are storing an array, you can use in_array to achieve the result you are looking for:
You can read more examples from https://www.w3schools.com/php/func_array_in_array.asp
Also you do not need to call
<?php //code ?>
in blade files, you can simply use{{ //code }}
to render it, you can read more on blade syntax from https://laravel.com/docs/9.x/bladeGood luck!
If you can fetch the value of
tool_id
from the database, use this.By default, this will add
selected
keywords to11
and13
.As the value of the select tag is being saved as an array, this can be simply done with the in_array condition as mentioned below:
Assuming the $IDsList (passed to the view blade from controller) have the value stored for the $tool->id