I want to store one more textbox data with attached function in Laravel 5.7.
I have three tables products, raws and product_raw. in Product_raw table I stored product_id and raw_id.
Controller.php
$post->products()->attach($request->product);
$post->raws()->attach($request->raws);
View.php
#foreach($raws as $value)
<div class="form-group">
<input type="text" name="quantity"><br>
<input type="checkbox" name="raws" value="raws[]"><br>
</div>
#endforeach
Related
I have module where I need checked the list checkbox if the ids determine that i have same ids to the another table. I have two table, Table 1 and Table 2
Table 1 - List of Items and all items loop in the checkbox
Table 2 - This table 2 are the stored ids where the user check the
items on table and submit. and those ids where inserted to the table
2.
So now. If the user try to open again the checkbox list items and if one of those items is already set make the checkbox automatically checked.
I have here my loop items function:
#foreach($details_items as $details_items_data)
<div class="col-md-3">
<div class="form-check">
<input type="checkbox" value="{{$details_items_data->adi_id}}" class="form-check-input csdtc_chkbox" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">{{$details_items_data->items}}</label>
</div>
</div>
#endforeach
Now I have here another loop where this loop is table 2
#foreach($details_set_check as $details_checker)
#endforeach
Currently have the output of this.
Try this out:
#foreach($details_items as $details_items_data)
<div class="col-md-3">
<div class="form-check">
<input type="checkbox" value="{{$details_items_data->adi_id}}" class="form-check-input csdtc_chkbox" id="exampleCheck1" #foreach($details_set_check as $details_checker) {{($details_items_data->adi_id == $details_checker->id)? 'checked':''}} #endforeach>
<label class="form-check-label" for="exampleCheck1">{{$details_items_data->items}}</label>
</div>
</div>
#endforeach
You have to make if condition.
<input #if(value in the lopp exists in your table) checked #endif />
i have a form that i increase the id of checkbox through a foreach with unknown size now when i submit i want to receive all of the sent data here is my code :
<form action="/somecontroller" method="post">
<div id="checkboxes" class="col-lg-2 text-center">
<input type="checkbox" name="rGroup" name="d{{$index}}" value="{{verta($pdates->date)->format('Y/m/d')}}" id="d{{$index}}"/>
<label class="whatever mt-3" for="d{{$index}}"> {{verta($pdates->date)->format('Y/m/d')}}
<hr>
{{$pdates->price}}</label>
</div>
</form>
and here is the controller :
$recived_data = $request->d{{$index}}; here i want to get all the checkboxes send by user
so how can i recive the data that user send which i dont know the number of checkboxes
You can use array syntax of the input element, and receive the array with selected items in the controller, so change your input checkbox to this:
<input type="checkbox" name="d[{{$index}}]" value="{{verta($pdates->date)->format('Y/m/d')}}" id="d{{$index}}"/>
Then in your controller:
$request->input('d'); // returns an array of indexes of all the selected checkboxes.
I am trying to set checkboxes checked based on database value. One user can have have multiple checkbox values.
Checkboxes are generated from database table called child_age_groups:
#foreach ($child_age_groups as $age)
<div class="checkbox checkbox-info checkbox-inline">
<input class="age_group_checkbox" type="checkbox" name="age_group[]" id="age_group{{$age->id}}" "/>
<label for="age_group{{$age->id}}">{{$age->age_group}}</label>
</div>
#endforeach
So in my controller I get all the options that user has like this
$nanny_babysitting_ages = Nanny_babysitting_ages::where('user_id', user()->id)->get();
My nanny_babysitting_ages table is this
user_id | ages
and my child_age_groups table where I populate the checkboxes are this:
id | age_group
How can I set the checkboxes selcted based on the values from database?
This is how I resolved it, I added foreach and if statement in the input to check if it the same value as from database:
<div class="form-group" id="ageCheckboxes">
#foreach ($child_age_groups as $age)
<div class="checkbox checkbox-info checkbox-inline">
<input class="age_group_checkbox" type="checkbox" value="{{$age->id}}" name="age_group[]" id="age_group{{$age->id}}" #foreach ($nanny_babysitting_ages as $ages) #if($age->id == $ages->ages ) checked #endif #endforeach />
<label for="age_group{{$age->id}}">{{$age->age_group}}</label>
</div>
#endforeach
</div>
you can use this "#checked(true)" like :-
<input class="custom-control-input army" type="checkbox" id="customCheckbox1" #checked($emp_plus->army != 0)>
I can't seem to figure this one out, nor how to start my query.
I have a form with different input field ID's
(customer_relationid, customer_brand, customer_goal, customer_floors, ....)
I have a mysql table with 3 columns (auto increment id, Key, Value)
The goal is to post all the info from the form row by row in mysql so that it results in this :
column id
this is just a auto increment, not important in this case
column KEY
relationid
brand
goal
floors
....
column VALUE
15
sony
music
3
.....
This is part of my form (the rest of the fields is the same):
<form id="calculator_form">
<fieldset id="generalInfo">
<legend>General Info</legend>
<h2>General Info</h2>
<label for="calculator_relationID">relationID:</label>
<input type="text" name="calculator_relationID" style="width:250px;" id="calculator_relationID" class="calculator_relationID">
<label for="calculator_brand">Brand:</label>
<input type="text" name="calculator_brand" style="width:250px;" id="calculator_brand" class="calculator_brand">
<label for="calculator_goal">Goal:</label>
<input type="text" name="calculator_goal" style="width:250px;" id="calculator_goal" class="calculator_goal">
<label for="calculator_floors">Floors:</label>
<input type="text" name="calculator_floors" style="width:250px;" id="calculator_floors" class="calculator_floors">
...
</fieldset>
How can I create the query as such so it knows it needs to insert it row by row for each form element?
Tnx in advance!
I'm trying to check the checkboxes on my edit view fetching the data from a table so the problem is all the checkboxes come unchecked. heres the code:
i don't know if this helps but in the table the data stores in an array there's not pivot table so i'm really trying to do it without using or making a pivot tablet.
<div class="form-group" style="padding-left: 1.4%">
{!!Form::label('estudio[]', 'Estudios Realizados* : ')!!}<br>
#foreach ($estudio as $key => $value)
#if(in_array($key, $my_estudio))
<input class="lista-estudio" name="estudio[]" type="checkbox" value="{{$key}}" id="estudio[]" checked> {{$value}}
#else
<input class="lista-estudio" name="estudio[]" type="checkbox" value="{{$key}}" id="estudio[]">{{$value}}
#endif
#endforeach
</div>