I'm trying to save multiple Label Text of Checkboxes. First, I'm saving chechbox value in a column of database table. But other than that, I have to save Label of each those checkbox checked in another column of table.
My table:
Schema::create('restaurant_offers', function (Blueprint $table) {
$table->increments('id');
.......
$table->string('additionalOptions')->nullable();
$table->string('additionalOptionsSum')->nullable();
......
});
My blade:
<label class="form-check-label" for="additionalOptionsSum" >
<input class="form-check-input calc" type="checkbox" id="additionalOptionsSum" name="additionalOptionsSum[]" value="19"> Delivery System
</label>
<label class="form-check-label" for="additionalOptionsSum" >
<input class="form-check-input calc" type="checkbox" id="additionalOptionsSum" name="additionalOptionsSum[]" value="29"> Takeaway System
</label>
<label class="form-check-label" for="additionalOptionsSum" >
<input class="form-check-input calc" type="checkbox" id="additionalOptionsSum" name="additionalOptionsSum[]" value="39"> Table Reservation System
</label>
My Controller:
$data = new RestaurantOffer;
......
$data["additionalOptionsSum"] = implode(",", $request->get("additionalOptionsSum"));
$data["additionalOptions"] = implode(',', $request->get("aditionaloptions"));
So, I have to save values and labels text of each checkbox checked as array in database. Values of additionalOptionsSum is working well. Now, I have to save additionalOptions too.
Example, if I check two checkboxes, the table in database, should be like this:
id| additionalOptions| additionalOptionsSum|
-----------------------------
1 | Delivery System, | 19, 29|
Takeaway System
For the moment it is looking like this:
id| additionalOptions| additionalOptionsSum|
-----------------------------
1 | | 19, 29|
Thank you in advance
Aucun commentaire:
Enregistrer un commentaire