I have a page for purchase order in that page i show data from table obat and i want to get selected checkbox using that data into table purchase order
This is my table obat
<table class="table table-bordered" style="margin-top:20px">
<tbody>
<tr class="text-center">
<th>No</th>
<td>Kode Obat</td>
<td>Nama Obat</td>
<td>Harga</td>
</tr>
#foreach ($obat as $key =>$o)
<tr>
<th class="text-center">
#foreach ($po as $po)
<input type="checkbox" name="select" id="select">
#endforeach
</th>
<td>
<input type="text" class="form-control" value="{{ $o->kode_obat }}">
</td>
<td>
<input type="text" class="form-control" value="{{ $o->nama_obat }}">
</td>
<td>
<input type="text" class="form-control" value="{{ $o->harga_obat }}">
</td>
</tr>
#endforeach
</tbody>
</table>
The checkbox(select) is from table purchase order but it can't show. if i did't use foreach its show
you can pass array also to check if it is in the array or not then you can this like below.
in your controller
public function edit($id)
{
$odat=Odat::all();
foreach($odat as $od)
{
$listod[]=$odat->select;
}
return view('yourbladefile',compact('roles','listod'));
}
then in your view
<input type="checkbox" name="select" #if (in_array(yourpurchaseordernamefromdb, $listod))
{{'checked'}} #endif>Selected</td>
personally i managed liked this. hope it helps
Related
i have an array of data in a form that i want to update.when i update only the last column updated while the inputs that i updated do change.for example, we have a column size, price, and stock. the size include small,medium, and large and their respective prices and stock number. when i update the price of small size,it doesnt update but rather it updates the medium size.same for the large size also.i havent understood why only a specfic column is updating yet i have added a foreach to loop all the columns when updating.here is my update function.
public function editattributes(Request $request,$id)
{
$merchadisedata=Merchadise::select('id','merch_name','merch_code','merch_image')->find($id);
if ($request->isMethod('post')){
$data=$request->all();
foreach($data['attrid'] as $key=>$attr){
if(!empty($attr)){
Productattribute::where(['id'=>$data['attrid'][$key]])
->update([
'productattr_price'=>$data['productattr_price'][$key],
'productattr_stock'=>$data['productattr_stock'][$key],
]);
}
$message='Product attributes have been updated successfully';
Session::flash('success_message',$message);
return redirect()->back();
}
}
return view('backend.merchadise.editproductattributes')->with(compact('merchadisedata'));
}
on dd($data);die(); i get the inputs i have filled
here is the form in the blade file that am submitting
<form method="post" action="{{ url('admin/edit-attributes/'.$merchadisedata->id) }}">
{{csrf_field()}}
<table id="products" class="table table-striped table-bordered nowrap" style="width:100%;">
<thead>
<tr>
<th>Attribute Size</th>
<th>Attribute Stock</th>
<th>Attribute Price</th>
<th>Attribute Sku</th>
</tr>
</thead>
<tbody>
#foreach ( $merchadisedata->merchadiseattributes as $attribute)
<input type="text" name="attrid[]" value="{{ $attribute->id }}" style="display: none"/>
<tr>
<td>{{ $attribute->productattr_size}}</td>
<td>
<input type="number" name="productattr_stock[]" value="{{ $attribute->productattr_stock }}" required=""/>
</td>
<td>
<input type="number" name="productattr_price[]" value="{{ $attribute->productattr_price }}" required=""/>
</td>
<td>{{ $attribute->productattr_sku }}</td>
</tr>
#endforeach
</tbody>
</table>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-sm btn-block">Submit</button>
</div>
</form>
where might i be going wrong in my code
I have a view that received a query result $necps from a controller, and I want to send to another controler with a form like below.
I am using a foreach to create the hidden inputs, but in the controller I get just the last record.
First question is : can I do that in a more elegant way? Sendind the entire query result at once?
Second : If not, how can I send all the array using foreach?
No Js please. Thanks a lot.
#if (isset($necps))
<div style="float:left; margin-left:20px;" >
<form style="display:inline;" action="{{route('mostra_varios_parts')}}" method="post">
#csrf
<button type="submit" class="btn btn-sm btn-mapa bi-globe texto_p"> Mapa</button>
#foreach($necps as $necp)
<input value="{{$necp->id_part}}" name="parts[id]" type="hidden">
<input value="{{$necp->latitude}}" name="parts[latitude]" type="hidden">
<input value="{{$necp->longitude}}" name="parts[longitude]" type="hidden">
<input value="{{$necp->nome_part}}" name="parts[nome_part]" type="hidden">
<input value="{{$necp->endereco}}" name="parts[endereco]" type="hidden">
#endforeach
</form>
</div>
<br>
<br>
<table class="table table-sm tabela-necessidade">
<thead>
<tr>
<th scope="col" class="texto_p">Nome</th>
<th scope="col" class="texto_p">Necessidade</th>
<th scope="col" class="texto_p">Categoria</th>
<th scope="col" class="texto_p">Data</th>
<th scope="col" class="texto_p">Quant</th>
<th scope="col" class="texto_p">Unidade</th>
<th scope="col" class="texto_p">Local</th>
<th scope="col" class="texto_p">Observações</th>
<!--<th scope="col" class="texto_p">Distância/Kms</th>-->
<th class="texto_p" colspan="1">Ações</th>
</tr>
</thead>
<tbody>
#if (count($necps)>0)
#foreach($necps as $necp)
<div>
<tr>
<td class="texto_p">{{$necp->nome_part}}</td>
<td class="texto_p">{{$necp->desc_nec}}</td>
<td class="texto_p">{{$necp->desc_cat}}</td>
<td class="texto_p">{{$necp->data}}</td>
<td class="texto_p">{{$necp->quant}}</td>
<td class="texto_p">{{$necp->desc_unid}}</td>
<td class="texto_p">{{$necp->endereco}} - {{$necp->cidade}}</td>
<td class="texto_p">{{$necp->obs}}</td>
<!--<td class="texto_p">{{$necp->distancia}}</td>-->
<td>
<form action="" method="post">
#csrf
<button type="submit" class="btn btn-sm btn-conectar bi-arrow-repeat texto_p"> Conectar</button>
<input value="{{$part->id}}" name="id_part_t" type="hidden">
<input value="{{$necp->id_nec_part}}" name="id_nec_part_t" type="hidden">
</form>
</td>
</tr>
</div>
#endforeach
#else
<td><td>Nenhum registro encontrado</td></td>
#endif
</tbody>
</table>
#endif
The name attribute for your hidden inputs need to be unique. you can post the fields as an array like so:
#foreach($necps as $necp)
<input value="{{$necp->id_part}}" name="parts[{{ $loop->index }}][id]" type="hidden">
<input value="{{$necp->latitude}}" name="parts[{{ $loop->index }}][latitude]" type="hidden">
<input value="{{$necp->longitude}}" name="parts[{{ $loop->index }}][longitude]" type="hidden">
<input value="{{$necp->nome_part}}" name="parts[{{ $loop->index }}][nome_part]" type="hidden">
<input value="{{$necp->endereco}}" name="parts[{{ $loop->index }}][endereco]" type="hidden">
#endforeach
with $loop->index as array key you post 1 array for every $necp
I Have a Blade Form that will execute Post Method, this is my blade
#foreach ($dataku as $row => $order)
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-12 text-center">
<b>{{ $order->delivery_order_no }}</b>
<input type="hidden" name="order[{{ $row }}][do_id]" value="{{ $order->id }}">
<input type="hidden" name="order[{{ $row }}][so_id]" value="{{ $order->sales_order->id }}">
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="table-responsive m-t-40" style="clear:both;">
<table class="table table-hover" style="font-size: 9pt;">
<thead>
<tr><th class="text-center">No</th>
<th class="text-center">SKUID</th>
<th class="text-center">Item Name</th>
<th class="text-center">UOM</th>
<th class="text-center">Qty So</th>
<th class="text-center">Qty Do</th>
<th class="text-center">Qty Confirm</th>
<th class="text-center">Qty Minus</th>
<th class="text-center">Remark Confirm</th>
</tr>
</thead>
<tbody>
#foreach ($order->delivery_order_details as $do =>$detOrder )
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $detOrder->skuid }}</td>
<td>{{ $detOrder->sales_order_detail->item_name }}</td>
<td>{{ $detOrder->uom->name }}</td>
<td>{{ $detOrder->sales_order_detail->qty }}</td>
<td>{{ $detOrder->qty_do }}</td>
<td>
<input type="hidden" class="form-control" name="order[{{ $row }}][detail[][{{ $do }}][skuid]]" value="{{ $detOrder->skuid}}">
<input type="number" class="form-control" name="order[{{ $row }}][detail[][{{ $do }}][qty_do]]" value="{{ $detOrder->qty_do }}">
</td>
<td>
<input type="number" min="0" class="form-control" name="order[{{ $row }}][detail[][{{ $do }}][qty_minus]]" value="0">
</td>
<td>
<input type="text" placeholder="Remark Confirm" class="form-control" name="order[{{ $row }}][detail[][{{ $do }}][remarks]]">
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
#endforeach
I Just want to get the data from the blade as an array ,... and then this is my controller
public function update(Request $request)
{
return $request->all();
}
I Get The Data Like This
is the return value from my blade $request->all(); correct? looks like something wrong ???
#sta provided an answer but I would make it more detailed:
When you build more complex structure (nested) in a html form input, every next key or list has to be surrounded by [].
So if you do just a nested keys it will be something[key1][key2][key3].
And if you do an array and a nested keys it will be something[key1][key2][][key3], where [] means that [key2] will be an array (and every array element will have a key3 key with provided value in input value attribute.
That's why this input name can't work:
order[0][detail[][0][skuid]]
but this one will work:
name="order[0][detail][0][qty_minus]
i have a view input like that :
<form class="form-group" action="/user6" method="post" enctype="multipart/form-data">
<table class="table table-striped">
<tbody><tr>
<th style="width: 10px">#</th>
<th>Pertanyaan</th>
<th style="width: 60px">Tidak Baik</th>
<th style="width: 60px">Baik</th>
</tr>
<div class="form-group">
<tr>
<td>1.</td>
<td><input class="form-control" style="border:none" type="text" name="question1" value="Kondisi, kebersihan, pelumasan bearing" readonly></td>
{{-- <td><input class="form-control" type="text" placeholder=".input-lg"></td> --}}
<td>
<label><input type="radio" name="answer1" value="tidak baik" checked></label>
</td>
<td>
<label><input type="radio" name="answer1" value="baik"></label>
</td>
</tr>
<tr>
<td></td>
<td> <input class="form-control" style="border:none" type="file" name="image" value="" readonly> </td>
</tr>
</div>
<tr>
<td></td>
<td> <div class="form-group">
<label>Catatan</label>
<textarea class="form-control" name="catatan" rows="3" placeholder="Enter ..." required></textarea>
</div>
</tr>
<input type="hidden" name="alat_id" value="7">
<input type="hidden" name="status" value="3 Bulanan">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</tbody>
</table>
<div class="box-footer">
<button type="submit" class="btn btn-primary" name="name" value="post">Submit</button>
</div>
</form>
and to save this i have controller :
public function store6(Request $request)
{
if($request->hasfile('image'))
{
foreach($request->file('image') as $file)
{
$name=$file->getClientOriginalName();
$file->move(public_path().'/images/', $name);
$data[] = $name;
}
}
$user = new pemeliharaan;
$id = Auth::user()->id;
$user->user_id = $id;
$user->alat_id = $request->alat_id;
$user->pertanyaan =json_encode($request->except
(['_token','name','alat_id','status','catatan']));
$user->catatan = $request->catatan;
$user->status = $request->status;
$user->save();
//dd($user);
return redirect('user/show6')->with('success', 'Data Telah Terinput');
}
before i add "enctype="multipart/form-data" , my view dont have error BUT cant display and saved image at directory . i want saved image to directory but cant saved .
i create a folder named 'images' at public . after i add enctype="multipart/form-data" . this view having error "htmlspecialchars() expects parameter 1 to be string, array given "
its my view after input :
<table class="table table-condensed">
<tbody><tr>
<th style="width: 10px">#</th>
<th>Pertanyaan</th>
<th>Hasil</th>
{{-- <th style="width: 40px">Label</th> --}}
</tr>
<tr>
<td>1.</td>
<td>{{ $pemeliharaan->pertanyaan['question1'] }}</td>
<td>
{{ $pemeliharaan->pertanyaan['answer1'] }}
</td>
</tr>
<tr>
<td>2.</td>
<td>{{ $pemeliharaan->pertanyaan['image'] }}</td>
<td>
{{ $pemeliharaan->pertanyaan['image'] }}
</td>
</tr>
<td><img src="{{ url('images/'.$pemeliharaan->pertanyaan['image'])}}"></td>
</tbody></table>
Something in your table is array, it's not a string so when you put it inside {{}}, it will show error.
You should check
$pemeliharaan->pertanyaan['question1']
$pemeliharaan->pertanyaan['answer1']
$pemeliharaan->pertanyaan['image']
by using dd() function.
Deal with one problem at a time. At present you are storing the image but not saving the path to the file, which you saved in $data. You are not using $data anywhere.
Then you have a problem rendering the new model in the view. This is a totally different issue and is caused by having non-string data passed to the htmlspecialchars function which is what {{ }} does.
Can anyone explains me, why the submit buttons no and yes in the following code not trigger?
Without the table, it works.
<table class="table">
<thead>
<tr>
<th scope="col">Group</th>
<th scope="col">Yes No</th>
</tr>
</thead>
#foreach($invitations as $invitation)
{!! Form::open(array('route'=>'store.groupentry')) !!}
<tbody>
<tr>
<td>
Do you want to enter group {{$invitation->group_name}}?
</td>
<td>
<input type="hidden" name="idgroup" value="{{ $invitation->idgroup }} "/>
<input type="hidden" name="groupname" value="{{ $invitation->group_name }} "/>
<button type="submit" class="btn btn-default" name = "submitbutton" value = "save">Yes</button>
<button type="submit" class="btn btn-default" name = "submitbutton" value = "nosave">No</button>
{{ csrf_field() }}
</td>
</tr>
</tbody>
{!! Form::close() !!}
#endforeach
</table>
Maybe not valid html generation. You generate many forms wrap many tbody in one table. I think you need create one form, and before submit set hidden values with js