Call to a member function hashName() on array - php

and I have a problem with how to enter images into the data base, in the case of the presence of input fields that increase or decrease in the case of addition or deletion
This is the code for adding data to the database
$products = $request->day_book_id;
for ($i=0; $i<count($products); $i++) {
$items = new Daybooks_units();
$items->debit= $request->debit[$i];
$items->creditor= $request->creditor[$i];
$items->data= $request->data[$i];
$items->reference= $request->reference[$i];
$items->files= $request->reference[$i];
$items->files = uploadImage('filesDayBooks',$request->images)[$i];
$items->dayBook_code= $request->dayBook_code[$i];
$items->fullAccounting_id= $request->fullAccounting_id[$i];
$items->day_book_id= $request->day_book_id[$i];
$items->branch_id= $request->branch_id[$i];
$items->save();
This is the code for the blade
<td style="padding:3px" >
<input type="text" class="search" name="search" required>
<select class="form-control search_list getData" id="search_list" name="fullAccounting_id[]"></select>
#error('fullAccounting_id')
<div class="alert alert-danger" role="alert">
{{ $message }}
</div>
#enderror
</td>
<td style="display:none" >
<input type="text" value=" " class=" form-control putParentId" name="ParentOfAccounting_manual_id[]">
</td>
<td style="display:none">
<input type="text" value=" " class=" form-control putCode" name="code_accountingManuals[]">
</td>
<td style="display:none">
<input type="text" value=" " class=" form-control debtor_creditor" name="debtor_creditor[]">
</td>
<td style="padding:3px">
<input type="text" value="0" class=" form-control totaldebit" onchange="getTotalRowPrice(this , '{{-500}}' )" name="debit[]">
#error('debit')
<div class="alert alert-danger" role="alert">
{{ $message }}
</div>
#enderror
</td>
<td style="width:100px;">
<input type="text" onchange="getTotalRowPrice(this , '{{-500}}' )" value="0" class=" form-control totalcreditor" name="creditor[]">
#error('creditor')
<div class="alert alert-danger" role="alert">
{{ $message }}
</div>
#enderror
</td>
<td style="padding:3px">
<input type="text" value="" class=" form-control" name="data[]">
</td>
<td style="width:100px;">
<select name="branch_id[]" required class="form-control">
<option></option>
#foreach($costCenters as $costCent)
<option value="{{$costCent->id}}">{{$costCent->name}}</option>
#endforeach
</select>
#error('branch_id')
<div class="alert alert-danger" role="alert">
{{ $message }}
</div>
#enderror
</td>
<td style="padding:3px">
<input type="text" class="form-control " name="reference[]" value="">
</td>
<td style="display:none;">
<input type="text" class="form-control " name="id_unit[]" value="{{ $id_unit }}">
</td>
<td style="display:none;">
<input type="text" class="form-control " name="daybooks_units[]" value="daybooks_units">
</td>
<td style="padding:3px">
<input type="file" name="images[]" multiple class="form-control" id="customFile">
</td>
<td style="padding:3px">
<input type="button" class="btn btn-success" name="add" id="add" value="add" style="color: white">
</td>
The function works smoothly if no images are inserted, but when images are uploaded, this error appears

I have no idea what your custom (not shared) uploadeImage function does, but the error SHOULD be here:
// You coded
$items->files = uploadImage('filesDayBooks',$request->images)[$i];
// It should be
$items->files = uploadImage('filesDayBooks',$request->images[$i]);
If that is not the error, please share uploadeImage code

Related

Laravel: Undefined variable in #foreach

I want to display order_details table on web, but #foreach loop says Undefined variable $order_details
Here is my #foreach loop
#foreach($order_details as $order_detail)
<tr>
<td>{{$order_detail->product_id}}</td>
<td>{{$order_detail->name}}</td>
<td>{{$order_detail->phone}}</td>
</tr>
#endforeach
My order controller contains this:
public function index()
{
$order_details=Order_Detail::all();
return view('orders.index',['order_details' => $order_details]);
}
index.blade.php contains only css and javascript code.
my index.blade.php is further connected to livewire(order.blade.php) like this
#livewire('order')
my livewire(order.blade.php) contains this code
<div class="col-lg-12">
<div class="row">
<div class="col-md-8">
<div class="card">
<div class="card-header"><h4 style="float:left">Order Products</h4>
<a href="#" style="float:right" class="btn btn-dark"
data-toggle="modal" data-target="#addproduct">
<i class="fa fa-plus"></i>Add new Product </a></div>
<div class="card-body">
<div class="my-2">
<form wire:submit.prevent="InsertoCart">
<input type="text" name="" wire:model="product_code"
id="" class="form-control" placeholder="Enter Product code">
</form>
</div>
#if(session()->has('success'))
<div class="alert alert-success">
{{session('success')}}
</div>
#elseif(session()->has('info'))
<div class="alert alert-info">
{{session('info')}}
</div>
#elseif(session()->has('error'))
<div class="alert alert-danger">
{{session('error')}}
</div>
#endif
<Table class="table table-bordered table-left">
<thead>
<tr>
<th></th>
<th>Product Name</th>
<th>Qty</th>
<th>Price</th>
<th>Discount (%)</th>
<th colspan="6">Total</th>
</tr>
</thead>
<tbody class="addMoreProduct">
#foreach($productIncart as $key=> $cart)
<tr>
<td class="no">{{$key + 1}}</td>
<td>
<input type="text" class="form-control" value="{{$cart->product->product_name}}">
</td>
<td width="15%">
<div class="row">
<div class="col-md-2">
<button wire:click.prevent="IncrementQty({{$cart->id}})"
class="btn btn-sm btn-success"> + </button>
</div>
<div class="col-md-1">
<label for="">{{$cart->product_qty}}</label>
</div>
<div class="col-md-2">
<button wire:click.prevent="DecrementQty({{$cart->id}})"
class="btn btn-sm btn-danger"> - </button>
</div>
</div>
</td>
<td>
<input type="number"
value="{{$cart->product->price}}" class="form-control">
</td>
<td>
<input type="number"
class="form-control">
</td>
<td>
<input type="number"
value="{{$cart->product_qty * $cart->product->price}}"
class="form-control total_amount">
</td>
<td><a href="#" class="btn btn-sm btn-danger rounded-circle">
<i class="fa fa-times" wire:click="removeProduct({{$cart->id}})"></i>
</a></td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header">
<h4>Total <b class="total1">{{$productIncart->sum('product_price')}}</b></h4>
</div>
<form action="{{route('orders.store')}}" method="POST">
#csrf
#foreach($productIncart as $key=> $cart)
<input type="hidden" class="form-control" name="product_id[]" value="{{$cart->product->id}}">
<!-- <input type="hidden" name="product_name[]" value="{{$cart->product_name}}"> -->
<input type="hidden" name="quantity[]" value="{{$cart->product_qty}}">
<input type="hidden" name="price[]"
value="{{$cart->product->price}}" class="form-control price" >
<input type="hidden" name="discount[]"
class="form-control discount" >
<input type="hidden" name="total_amount[]"
value="{{$cart->product_qty * $cart->product->price}}"
class="form-control total_amount" >
#endforeach
<div class="card-body">
<div class="btn-group">
<button type="button"
onclick="PrintReceiptContent('print')"
class="btn btn-dark"> <i class="fa fa-print"></i>Print
</button>
<button type="button"
onclick="PrintReceiptContent('print')"
class="btn btn-primary"> <i class="fa fa-print"></i>History
</button>
<button type="button"
onclick="PrintReceiptContent('print')"
class="btn btn-danger"> <i class="fa fa-print"></i>Report
</button>
</div>
<div class="panel">
<div class="row">
<table class="table table-striped">
<tr>
<td>
<label for="">Customer Name</label>
<input type="text" name="customer_name" id="" class="form-control">
</td>
<td>
<label for="">Customer Phone</label>
<input type="number" name="customer_phone" id="" class="form-control">
</td>
</tr>
</table>
<td>Payment Method <br>
<div class="">
<span class="radio-item">
<input type="radio" name="payment_method" id="payment_method"
class="true" value="cash" checked="checked">
<label for="payment_method"><i class="fa fa-money-bill text-success"></i>Cash</label>
</span>
<span class="radio-item">
<input type="radio" name="payment_method" id="payment_method"
class="true" value="bank transfer">
<label for="payment_method"><i class="fa fa-university text-danger"></i>Bank Transfer</label>
</span>
<span class="radio-item">
<input type="radio" name="payment_method" id="payment_method"
class="true" value="credit Card">
<label for="payment_method"><i class="fa fa-credit-card text-info"></i>Credit Card</label>
</span>
</td><br>
<td> Payment
<input type="number" wire:model="pay_money" name="paid_amount"
id="paid_amount" class="form-control">
</td>
<td> Returning Change
<input type="number" wire:model="balance" name="balance"
id="balance" readonly class="form-control">
</td>
<td>
<button class="btn-primary btn-lg btn-block mt-3">Save</button>
</td>
<td>
<button class="btn-danger btn-lg btn-block mt-2">Calculator</button>
</td>
<div class="text-center">
<i class=" fa fa-sign-out-alt"></i>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- Order Details display -->
<div class="container-fluid">
<div class="col-lg-12">
<div class="row">
<div class="col-md-9">
<div class="card">
<div class="card-header"><h4 style="float:left">Recent Orders</h4>
</div>
<div class="card-body">
<Table class="table table-bordered table-left">
<thead>
<tr>
<th>id</th>
<th>Order Id</th>
<th>Product Name</th>
<th>Quantity</th>
<th>Price</th>
<th>Total Amount</th>
<th>Discount</th>
</tr>
</thead>
#foreach($order_details as $order_detail)
<tr>
<td>{{$order_detail->product_id}}</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>{{$order_detail->unitprice}}</td>
<td>{{$order_detail->amount}}</td>
<td></td>
</tr>
#endforeach
<tbody>
</Table>
</div>
</div>
</div>
</div>
</div>
</div>
What I noticed in your code is that you might be expecting an answer in another place while your code is running somewhere else.
First of all, you are writing a show(Order $order) function that collects parameters, while you are outputting it in the index page, so where you are calling the show function will expect a parameter, while the index will not expect a parameter

How to add additional input with value in modal before form submit in laravel

I use laravel 7. I want to add additional modal with value before submit.
When I try to update data without additional modal, the update works correctly. But when I add the additional modal with value, the program success but my update not works correnctly. This is my form (blade view):
<div class="col-md-10">
<form method="POST" action="{{ url('/quotation/updateQuotation', $id) }}"
enctype="multipart/form-data">
#csrf
<div class="card">
<div class="card-body bg-light-white ">
<div class="tab-content">
<table width="100%">
<tr>
<td>Quotation No<span class="required" style="color: red">*</span></td>
<td>
<div class="form-group col-md-9">
<span style="display: flex;">
<input type="text" name="qno" style="width: 20%;"
class="form-control form-control-sm"
value="{{ $qno }}" readonly />
<input type="text" name="quotation_no" style="width: 60%;"
class="form-control form-control-sm"
value="{{ $quotation->quotation_no }}" readonly />
</span>
</div>
</td>
<td>Quotation Date<span class="required" style="color:red"></td>
<td>
<div class="form-group col-md-9">
<input type="date" name="quotation_date"
class="form-control form-control-sm"
value="{{ $quotation->quotation_date }}" />
</div>
</td>
</tr>
<tr>
<td>Ref. No</td>
<td>
<div class="form-group col-md-9">
<input type="text" name="ref_no" style="width: 80%"
class="form-control form-control-sm"
value="{{ $quotation->ref_no }}" />
</div>
</td>
<td>Request Date</td>
<td>
<div class="form-group col-md-9">
<input type="date" name="request_date"
class="form-control form-control-sm"
value="{{ $quotation->request_date }}" />
</div>
</td>
</tr>
<tr>
<td>Request By</td>
<td>
<div class="form-group col-md-9">
<input type="text" name="request_by"
class="form-control form-control-sm"
value="{{ $quotation->request_by }}" style="width: 80%" />
</div>
</td>
<td>Currency<span class="required" style="color:red"></td>
<td>
<div class="form-group col-md-9">
<select class="form-control selectpicker" data-live-search="true"
style="width: 80%;" aria-label="1 -10" id="currency"
name="currency">
{{-- munculkan option data dari table --}}
<option value="{{ $quotation->currency }}" selected>
{{ $quotation->currency }}</option>
{{-- list option dari table currency --}}
#foreach ($curency as $val2)
<option value="{{ $val2->code }}"
data-token="{{ $val2->name }}">{{ $val2->code }}
</option>
#endforeach
</select>
</div>
</td>
</tr>
<tr>
<td>Insurance Period<span class="required" style="color:red"></td>
<td>
<div class="form-group col-md-9">
<span style="display: flex;">
<input type="date" name="start_period" style="width: 40%;"
class="form-control form-control-sm"
value="{{ $quotation->start_period }}" />
<input type="date" name="end_period" style="width: 40%;"
class="form-control form-control-sm"
value="{{ $quotation->end_period }}" />
</span>
</div>
</td>
<td>Quotation Type</td>
<td>
<div class="form-group col-md-9">
<select name="quotation_type" class="form-control" id="quotation_type">
#if ($quotation->quotation_type == 1)
<option value="1">Tipe 1</option>
#endif
#if ($quotation->quotation_type == 2)
<option value="2">Tipe 2</option>
#endif
<option value="1">Tipe 1</option>
<option value="2">Tipe 2</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Ceding<span class="required"></td>
<td>
<div class="form-group col-md-9">
<select class="form-control selectpicker" data-live-search="true"
name="ceding_id" style="width: 80%;" aria-label="1 -10" required>
#if ($quotation->ceding_id == null)
<option value="" data-tokens=""></option>
#endif
#foreach ($cedding as $val2)
#if ($quotation->ceding_id == $val2->code)
<option value="{{ $val2->code }}"
data-tokens="{{ $val2->name }}">
{{ $val2->code . '-' . $val2->name }}</option>
#endif
#endforeach
#foreach ($cedding as $val2)
<option value="{{ $val2->code }}"
data-tokens="{{ $val2->name }}">
{{ $val2->code . '-' . $val2->name }}</option>
#endforeach
</select>
</div>
</td>
<td>Payment Mode</td>
<td>
<div class="form-group col-md-9">
<select class="form-control selectpicker" data-live-search="true"
aria-label="1 -10" name="payment_mode" id="payment_mode">
#if ($quotation->payment_mode == 1)
<option value="1">Annually</option>
#endif
#if ($quotation->payment_mode == 2)
<option value="2">Semi Annually</option>
#endif
#if ($quotation->payment_mode == 4)
<option value="4">Quaterly</option>
#endif
#if ($quotation->payment_mode == 12)
<option value="12">Monthly</option>
#endif
<option value="1">Annually</option>
<option value="2">Semi Annually</option>
<option value="4">Quaterly</option>
<option value="12">Monthly</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Company<span class="required"></td>
<td>
<div class="form-group col-md-9">
<select class="form-control selectpicker" data-live-search="true"
name="company_profile" style="width: 80%;" aria-label="1 -10"
required>
#if ($quotation->company_profile == null)
<option value="" data-tokens=""></option>
#endif
#foreach ($company as $val2)
#if ($quotation->company_profile == $val2->company_profile)
<option value="{{ $val2->company_profile }}"
data-tokens="{{ $val2->company_profile }}" selected>
{{ $val2->company_profile }}</option>
#endif
#endforeach
#foreach ($company as $val2)
<option value="{{ $val2->company_profile }}"
data-tokens="{{ $val2->company_profile }}">
{{ $val2->company_profile }}</option>
#endforeach
</select>
</div>
</td>
<td>Installment<span class="required" style="color:red"></td>
<td>
<div class="form-group col-md-9">
<input id="installment" type="text" name="qty_installment"
class="form-control" readonly
value="{{ $quotation->qty_installment }}">
</div>
</td>
</tr>
<tr>
<td>Product Brand<span class="required"></td>
<td>
<div class="form-group col-md-9">
<select class="form-control selectpicker" data-live-search="true"
name="product_brand" style="width: 80%;" aria-label="1 -10"
required>
#if ($quotation->product_brand == null)
<option value="" data-tokens=""></option>
#endif
#foreach ($productbrand as $val2)
#if ($quotation->product_brand == $val2->product_brand && $quotation->company_profile == $val2->company_profile && $quotation->ceding_id == $val2->ceding_id)
)
<option value="{{ $val2->product_brand }}"
data-tokens="{{ $val2->product_brand }}">
{{ $val2->product_brand . '-' . $val2->description }}
</option>
#endif
#endforeach
#foreach ($productbrand as $val2)
<option value="{{ $val2->product_brand }}"
data-tokens="{{ $val2->product_brand }}">
{{ $val2->product_brand . '-' . $val2->description }}
</option>
#endforeach
</select>
</div>
</td>
<td>Quotation Category</td>
<td>
<div class="form-group col-md-9">
<select name="quotation_category" class="form-control"
id="quotation_category">
#if ($quotation->quotation_category == 'konvensional')
<option value="konvensional">Konvensional</option>
#endif
#if ($quotation->quotation_category == 'syariah')
<option value="syariah">Syariah</option>
#endif
<option value="konvensional">Konvensional</option>
<option value="syariah">Syariah</option>
</select>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="align-items-right">
{{-- <button class="btn btn-success" style="float: right; margin: 10px;">
{{ __('Simulasi Premi ') }}
</button> --}}
{{-- <input type="submit" class="btn btn-success" value="Update"
style="float: right; margin: 10px;"> --}}
<button type="button" class="btn btn-success" data-id="2014-123456" data-toggle="modal"
data-target="#modalRevisi">Update</button>
</div>
</div>
{{-- start here modal revisi --}}
<div id="modalRevisi" class="modal fade" role="dialog">
<div>
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="height:50px;">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<label>Revisi:</label>
<select name="tipe_revisi" id="tipe_revisi" class="form-control">
<option value="internal">Internal</option>
<option value="eksternal">Eksternal</option>
</select>
</div>
<div class="modal-footer text-center" style="display:inline;">
<!-- <input type="submit" class="btn btn-primary" value="Cash" name="login" style="background-color:rgb(0,30,66); "> -->
<button type="button" class="btn btn-danger"
data-dismiss="modal">Cancel</button>
<input type="submit" class="btn btn-primary" value="Submit" name="submit"
style="background-color:rgb(0,30,66); ">
</div>
</div>
</div>
</div>
{{-- </form> --}}
</div>
{{-- end here modal revisi --}}
</form>
</div>
This is th updateController:
public function updateQuotation(Request $request,QuotationLog $log, $id)
{
// dd($request);
$user = Auth::user();
$validator = $request->validate([
'qno' => 'required',
]);
// dd($request->product_plan);
$quotation = Quotation::find($id);
if ($validator) {
try{
$quotation = Quotation::find($id);
$quotation->qno = $request->qno;
$quotation->quotation_no = $request->quotation_no;
$quotation->quotation_date = $request->quotation_date;
$quotation->ref_no = $request->ref_no;
$quotation->request_date = $request->request_date;
$quotation->request_by = $request->request_by;
$quotation->currency = $request->currency;
$quotation->start_period = $request->start_period;
$quotation->end_period = $request->end_period;
$quotation->quotation_type = $request->quotation_type;
$quotation->quotation_category = $request->quotation_category;
$quotation->payment_mode = $request->payment_mode;
$quotation->qty_installment = $request->qty_installment;
$quotation->ceding_id = $request->ceding_id;
$quotation->company_profile = $request->company_profile;
$quotation->product_brand = $request->product_brand;
$quotation->expired_claim_receipt = $request->expired_claim_receipt;
$quotation->overwrite_membership_premi_f = $request->overwrite_membership_premi_f;
$quotation->prorate_claim_f = $request->prorate_claim_f;
$quotation->uw_year = $request->uw_year;
$quotation->user = $user->name;
$quotation->tipe_revisi = $user->tipe_revisi;
$quotation->save();
//update table log
$log->qno = $request->qno;
$log->quotation_no = $request->quotation_no;
$log->quotation_date = $request->quotation_date;
$log->ref_no = $request->ref_no;
$log->request_date = $request->request_date;
$log->request_by = $request->request_by;
$log->currency = $request->currency;
$log->start_period = $request->start_period;
$log->end_period = $request->end_period;
$log->quotation_type = $request->quotation_type;
$log->quotation_category = $request->quotation_category;
$log->payment_mode = $request->payment_mode;
$log->ceding_id = $request->ceding_id;
$log->company_profile = $request->company_profile;
$log->product_brand = $request->product_brand;
$log->expired_claim_receipt = $request->expired_claim_receipt;
$log->overwrite_membership_premi_f = $request->overwrite_membership_premi_f;
$log->prorate_claim_f = $request->prorate_claim_f;
$log->uw_year = $request->uw_year;
$log->remarks = $request->remarks;
$log->kind_of_contract = $request->kind_of_contract;
$log->user_id = $user->id;
$log->user_name = $user->name;
$log->ip_address = $this->get_client_ip();
$log->action = 'EDIT';
$log->tipe_revisi = $user->tipe_revisi;
$log->save();
$notification = array(
'message' => 'Quotation updated successfully!',
'alert-type' => 'success'
);
return back()->with($notification);
}catch (\Illuminate\Database\QueryException $ex) {
dd($ex);
$message = DB::table('health_sys_error')
->select('error_message')
->where('error_id','=',$ex->errorInfo[1])
->first();
$notification = array(
'message' => $message->error_message == null ? 'Error, Contact Admin!' : $message->error_message,
'alert-type' => 'error'
);
return back()->with($notification)->withInput();
}
} else {
return back()->with($validator)->withInput();
}
}
I have done to add in models and migration. My program return success, but tipe_revisi field not inserted. Why?
use
$quotation->tipe_revisi = $request->tipe_revisi;
instead
$quotation->tipe_revisi = $user->tipe_revisi;
because you get data from form
I think you should change this code, becoz this is a field name in form.
$user->tipe_revisi
to
$request->tipe_revisi

Double loop foreach laravel 5.5 blade

Tying to access item tables in first loop and values of the 2nd loop in a select in laravel. How do i do this? I get an error:
Trying to get property 'unit_abb' of non-object (View: C:\xampp\htdocs\ein\IPPS\resources\views\pr-items.blade.php)
Here is my code:
pr-items.blade
#foreach($list as $indexKey => $list)
<form class="form-horizontal" role="form" method="POST" action="{{ url('/update_items',$list->id) }}" autocomplete="off" >
{{ csrf_field() }}
{{ method_field('PATCH') }}
<input type="hidden" value="{{$list->pr_form_number}}" name='prlist' id='prlist'>
<tr>
<th>
</th>
<td>
<input type="text" class="form-control custom-border input-sm" value="{{$list->pr_qty}}" name="qtylist" id="qtylist" >
</td>
<td>
<select id="department" type="text" class="form-control custom-border input-sm" name="unitlist" id="unitlist">
#foreach ($units as $key => $newunit)
#if ($loop->parent->first)
<option value="{{$newunit->unit_abb}}" #if($newunit->unit_abb == $list->pr_unit) selected #endif>{{$newunit->unit_name}}</option>
#endif
#endforeach
</select>
</td>
<td>
<input type="text" class="form-control custom-border input-sm" value="{{$list->pr_description}}" name="descriptionlist" id="descriptionlist" >
</td>
<td>
<input type="text" class="form-control custom-border input-sm money-inp" value="{{$list->pr_cost_per_unit}}" name="cpulist" id="cpulist">
</td>
<td>
<input type="text" class="form-control custom-border input-sm money-inp" value="{{$list->pr_estimated_cost}}" disabled>
</td>
<td class="text-center">
<button type="submit" class="btn btn-warning btn-sm glyphicon glyphicon-pencil"></button>
<a class="btn btn-danger btn-sm glyphicon glyphicon-minus" href="{{route('pr.delete',$list->id)}}"></a>
</td>
</tr>
</form>
#endforeach

Laravel data not going appropriately into the database

What i need is if i get first element id of MOB/TR/1743 then press the mark button data which relevant to that id must go the database.
This is what should in the database.
But this is what i'm getting into the database. That means getting another column data into database.
Here is the view of that.
<div class="row">
<section id="feature" class="section-padding wow fadeIn delay-05s">
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-6 col-xs-12">
<div class="wrap-item text-center">
<div class="jumbotron">
<div class="item-img">
<img src="images/ser02.png">
</div>
<div class="form-group">
<form action="search" method="post" class="form-inline">
<select name="institute" id="institute">
<option selected="selected" value="id">Trainee Id</option>
<option value="full_name">Trainee Name</option>
<label for="Search">Name</label>
</select>
<input type="text" name="search" /><br>
<input type="hidden" value="{{ csrf_token() }}" name="_token" />
<input type="submit" name="submit" value="Search">
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<div class="col-md-12 col-sm-6 col-xs-12">
<div class="panel panel-default">
<div class="panel-body">
<table class="table table-striped">
<thead>
<th>Trainee ID</th>
<th>Name with Initials</th>
<th>Time</th>
<th>Mark Here!</th>
</thead>
<tbody>
<form action="{{route('TraineeAttendance.store')}}" method="post" >
{{ csrf_field() }}
#foreach($items as $item)
<tr>
<td>
<div class="form-group">
<input type="text" name="trainee_id" class="form-control" value="{{ $item->trainee_id }}">
</div>
</td>
<td>
<div class="form-group">
<input type="text" name="name" class="form-control" value="{{ $item->name_with_initials }}">
</div>
</td>
<td>
<label><input type="checkbox" name="time" id="time" value="time"> Time</label>
</td>
<td>
<input type="submit" class="btn btn-info">
</td>
</tr>
#endforeach
</form>
</tbody>
</table>
</div>
</div>
</div>
Why i`m getting wrong data?
try this hope it helps
#foreach($items as $item)
<form action="{{route('TraineeAttendance.store')}}" method="post" >
{{ csrf_field() }}
<tr>
<td>
<div class="form-group">
<input type="text" name="trainee_id" class="form-control" value="{{ $item->trainee_id }}">
</div>
</td>
<td>
<div class="form-group">
<input type="text" name="name" class="form-control" value="{{ $item->name_with_initials }}">
</div>
</td>
<td>
<label><input type="checkbox" name="time" id="time" value="time"> Time</label>
</td>
<td>
<input type="submit" class="btn btn-info">
</td>
</tr>
</form>
#endforeach

display many rows using a foreach in an array

Im'y trying to do something like that but it does not work.
$resDisplayFormation is a query which returns many rows, and i need to display all the rows in my table, this file is a file called by an ajax function that's why i have to do my foreach a like that
UPDATE :
<?php
include('opendb2.php');
if(isset($_POST['idSalarie'])){
$displayFormation = $bdd->prepare('SELECT * FROM FORMATION WHERE form_id_user = :idSalarie ');
$displayFormation->bindParam(':idSalarie', $_POST['idSalarie']);
$displayFormation->execute();
$resDisplayFormation=$displayFormation->fetch(PDO::FETCH_ASSOC);
$displayForm = $bdd->prepare(
'SELECT poste_nom, ups_type_contrat, serv_nom, serv_id_resp, user_credit_cpf, user_indice_salarial, form_intitule, form_organisme, form_date, form_duree,
FLOOR( DATEDIFF( CURDATE( ) , user_dateentree ) /365 ) AS dateEntree
FROM USER
INNER JOIN USER_POSTE_SERVICE
ON USER.user_id= USER_POSTE_SERVICE.ups_poste_id
INNER JOIN POSTE
ON USER_POSTE_SERVICE. ups_poste_id = POSTE.poste_id
INNER JOIN SERVICE
ON USER_POSTE_SERVICE.ups_id_serv = SERVICE.serv_id
INNER JOIN FORMATION
ON FORMATION.form_id_user = USER.user_id
WHERE user_id = :idSalarie
ORDER BY user_nom ASC');
$displayForm->bindParam(':idSalarie', $_POST['idSalarie']);
$displayForm->execute();
$resDisplayForm=$displayForm->fetch(PDO::FETCH_ASSOC);
$data = array( 'resDisplayForm'=>'');
foreach ($resDisplayForm as $key => $value) {
$data['resDisplayForm'][$key] .= $value;
}
$data['salarie'] = '
<div class="form-group">
<label for="poste_nom" class="col-sm-2 control-label">Poste occupé</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="poste_nom" readonly>
</div>
</div>
<div class="form-group">
<label for="ups_type_contrat" class="col-sm-2 control-label">Type de contrat</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="ups_type_contrat" readonly>
</div>
</div>
<div class="form-group">
<label for="serv_nom" class="col-sm-2 control-label" readonly>Service</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="serv_nom" readonly>
</div>
</div>
<div class="form-group">
<label for="serv_id_resp" class="col-sm-2 control-label" readonly>Responsable</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="serv_id_resp" readonly>
</div>
</div>
<div class="form-group">
<label for="user_credit_cpf" class="col-sm-2 control-label" readonly>Crédits CPF</label>
<div class="col-sm-2">
<input type="text" class="form-control" name="user_credit_cpf" readonly>
</div>
<label for="user_indice_salarial" class="col-sm-2 control-label" readonly>Indice Salarial</label>
<div class="col-sm-1">
<input type="text" class="form-control" name="user_indice_salarial" readonly>
</div>
<label for="dateEntree" class="col-sm-2 control-label">Ancienneté</label>
<div class="col-sm-2 input-group">
<input type="text" class="form-control" name="dateEntree" aria-describedby="basic-addon2" readonly>
<span class="input-group-addon" id="basic-addon2">années</span>
</div>
</div>';
$data['formation'] .= '
<div class="table-responsive">
<table class="table table-bordered" style="width: auto !important;">
<thead style="font-weight: bold;">’’
<tr>
<td>N</td>
<td>Intitulé</td>
<td>Organisme</td>
<td>Date</td>
<td>Durée (en heures)</td>
<td>Eval. à chaud / à froid</td>
<td>Dispositif utilisé</td>
</tr>
</thead>
<tbody class="table-striped">';
foreach ($resDisplayFormation as $ligne) {
$data['formation'] .= '
<tr>
<td>
</td>
<td>
<input type="text" class="form-control" name="form_intitule" id="form_intitule" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_organisme" id="form_organisme" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_date" id="form_date" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_duree" id="form_duree" readonly>
</td>
<td></td>
<td></td>
</tr>';
}
$data['formation'] .= '
</tbody>
</table>
</div>';
}
echo json_encode($data);die;
?>
My AJAX :
jQuery(document).ready(function($) {
$('#idSalarie').change(function(){
//on recupere la valeur de l'attribut value pour afficher tel ou tel resultat
var req=$('#idSalarie').val();
//requête ajax, appel du fichier function.php
$.ajax({
type: "POST",
url: "lib/function.php",
data: "idSalarie="+req,
dataType : "json",
//affichage de l'erreur en cas de problème
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest + '--' + textStatus + '--' + errorThrown);
},
//function s'il n'y a pas de probleme
success:function(data){
//On affiche la réponse du serveur
$('.salarie').empty();
$('.salarie').prepend(data.salarie);
$('input[name=poste_nom]').val(data.resDisplayForm.poste_nom).val();
$('input[name=ups_type_contrat]').val(data.resDisplayForm.ups_type_contrat).val();
$('input[name=serv_nom]').val(data.resDisplayForm.serv_nom).val();
$('input[name=serv_id_resp]').val(data.resDisplayForm.serv_id_resp).val();
$('input[name=user_credit_cpf]').val(data.resDisplayForm.user_credit_cpf).val();
$('input[name=dateEntree]').val(data.resDisplayForm.dateEntree).val();
$('input[name=user_indice_salarial]').val(data.resDisplayForm.user_indice_salarial).val();
$('.formation').empty();
$('.formation').prepend(data.formation)
$('input[name=form_id]').val(data.resDisplayForm.form_id).val();
$('input[name=form_intitule]').val(data.resDisplayForm.form_intitule).val();
$('input[name=form_organisme]').val(data.resDisplayForm.form_organisme).val();
$('input[name=form_date]').val(data.resDisplayForm.form_date).val();
$('input[name=form_duree]').val(data.resDisplayForm.form_duree).val();
}
});
});
});
Inside foreach instead of
$data['formation'] = '
you had to write
$data['formation'] .= '
and after foreach you also had to write
$data['formation'] .= '
This will concatenate all of you rows in correct HTML table
UPDATE
In this part of code you didn't get any value from $ligne param and dont write it in table cells. Thats why you will get 6 identical rows
foreach ($resDisplayFormation as $ligne) {
$data['formation'] .= '
<tr>
<td>
</td>
<td>
<input type="text" class="form-control" name="form_intitule" id="form_intitule" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_organisme" id="form_organisme" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_date" id="form_date" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_duree" id="form_duree" readonly>
</td>
<td></td>
<td></td>
</tr>';
}
It should be smth like this
foreach ($resDisplayFormation as $ligne) {
$data['formation'] .= '
<tr>
<td>
</td>
<td>
<input type="text" class="form-control" name="form_intitule" id="form_intitule" value='.$ligne["form_intitule"].' readonly>
</td>
<td>
<input type="text" class="form-control" name="form_organisme" id="form_organisme" value='.$ligne["form_organisme"].' readonly>
</td>
<td>
<input type="text" class="form-control" name="form_date" id="form_date" value='.$ligne["form_date"].' readonly>
</td>
<td>
<input type="text" class="form-control" name="form_duree" id="form_duree" value='.$ligne["form_duree"].' readonly>
</td>
<td></td>
<td></td>
</tr>';
}
$data['formation'] .= '
<div class="table-responsive">
<table class="table table-bordered" style="width: auto !important;">
<thead style="font-weight: bold;">’’
<tr>
<td>N</td>
<td>Intitulé</td>
<td>Organisme</td>
<td>Date</td>
<td>Durée (en heures)</td>
<td>Eval. à chaud / à froid</td>
<td>Dispositif utilisé</td>
</tr>
</thead>
<tbody class="table-striped">';
foreach ($resDisplayFormation as $ligne) {
$data['formation'] .= '
<tr>
<td>
</td>
<td>
<input type="text" class="form-control" name="form_intitule" id="form_intitule" value="'.$ligne['form_intitule'].'" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_organisme" id="form_organisme" value="'.$ligne['form_organisme'].'" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_date" id="form_date" value="'.$ligne['form_date'].'" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_duree" id="form_duree" value="'.$ligne['form_duree'].'" readonly>
</td>
<td></td>
<td></td>
</tr>';
}
$data['formation'] .= '
</tbody>
</table>
</div>';
}
echo json_encode($data); die;

Categories