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
Related
I am building a system so the user can request for multiple things, and I want to be able to visualize the details about each request (individually) made in the system.
The current method gives me everything at once, and not separated.
Here is the part of the code
The controller
public function verDetalhesKeys($id)
{
$detalhes = DB::table('keysRequest')
->where('keysRequest.id','=', $id)
->select('keysRequest.*')
->get();
return view('Admin.keysRequestDetails',compact('detalhes'));
}
The route
Route::get('/detalhesK/{id}', 'AdminController#verDetalhesKeys') -> name('detalhesK');
The button to Visualize the details
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Department</th>
<th>Site</th>
<th>Pourpose</th>
<th>From</th>
<th>To</th>
</tr>
</thead>
<tbody>
#foreach($keys as $s)
<tr>
<td>{{$s->name}}</td>
<td>{{$s->email}}</td>
<td>{{$s->department}}</td>
<td>{{$s->site}}</td>
<td>{{$s->purpose}}</td>
<td>{{$s->till}}</td>
<td>{{$s->until}}</td>
<td style="display:none;">{{$s->id}}</td>
<td><a class="btn btn-info btn-md" href="{{ route('detalhesK',['id' => $s->id])}}" style="background-color:#00a3b3;"><i class="fa fa-eye" aria-hidden="true"></i></a></td>
</tr>
#endforeach
</tbody>
</table>
The page of the details
<div class="container">
<div class="row justify-content-center">
<div class="col-16 col-md-12 col-lg-12 pb-7">
<!--Form with header-->
<form method="post">
#foreach($detalhes as $d)
<div class="card border-primary rounded-0">
<div class="card-header p-0">
<div class="bg-info text-white text-center py-2">
<h3>Requisição de Chaves Detalhes || Keys Request Details</h3>
</div>
</div>
<div class="card-body p-3">
<!--Body-->
<div class="form-group">
<label>Nome || Name</label>
<input type="text" class="form-control" placeholder="{{$d->name}}" readonly>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" placeholder="{{$d->email}}" readonly>
</div>
<div class="form-group">
<label>Departamento || Department</label>
<textarea class="form-control" placeholder="{{$d->department}}" readonly></textarea>
</div>
<div class="form-group">
<div class="input-group mb-2">
<label>Local || Site</label>
<textarea class="form-control" placeholder="{{$d->site}}" readonly></textarea>
</div>
<br>
<div class="form-group">
<label>Finalidade || Purpose</label>
<input type="Quantidade" class="form-control" placeholder="{{$d->purpose}}" readonly>
</div>
<div class="form-group">
<label>Período de uso das chaves || Period of use of the keys</label>
<textarea class="form-control" placeholder="{{$d->till}} - {{$d->until}}" readonly></textarea>
</div>
<div class="text-center">
<a class="btn btn-danger" href=""><font color="white"> Rejeitar || Refuse </font></a>
<a class="btn btn-success" href=""><font color="white"> Validar || Validate </font></a>
</div>
</div>
#endforeach
</div>
</form>
<!--Form with header-->
</div>
first of all is 'id' the column to primary key in your database table, you need to make sure it is so you wont have dublicate products.Edit your query to $detalhes = DB::table('keysRequest')->find(id);.
After doing that, wont need to use a loop to ouput your result since its only 1 item. just use {{$detalhes->something}}
I am trying to get some data from a database and show them in a bootstrap table in php. but the php file only shows navigation bar. it does not show the table or the form. I have checked the connection which is fine. even if connection was wrong it should at least show the table headers and form labels. which it does not.
<?php
include 'adminlogincheck.php';
include 'dbcarsconfig.php';
include 'adminheader.php';
?>
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-md-8">
<!-- session response-->
<?php if(isset($_SESSION['response'])){ ?>
<div class="alert alert-<?= $_SESSION['res_type']; ?> alert-dismissible">
<button type="button" class="close" data-dismiss="alert">×</button>
<?= $_SESSION['response']; ?>
</div>
<?php } unset($_SESSION['response']);?>
<?php
$query="SELECT * FROM cars";
$stmt=$conn->prepare($query);
$stmt->execute();
$result=$stmt->get_result();
?>
<table class="table table-dark table-striped table-hover">
<thead>
<tr>
<th>Thumbnail</th>
<th>ID</th>
<th>Reg no</th>
<th>Make</th>
<th>Model</th>
<th>Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php while($row=$result->fetch_Assoc()){?>
<tr>
<td><img src="<?= $row['image1']?>" width="100" height="50"></td>
<td><?= $row['id']?></td>
<td><?= $row['carreg']?></td>
<td><?= $row['make']?></td>
<td><?= $row['model']?></td>
<td><?= $row['price']?></td>
<td> Edit/View</td>
<td> Delete</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="col-md-4">
<form action="actioncars.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?= $id; ?>">
<div class="form-group">
<input type="text" name="carreg" class="form-control" placeholder="Enter car reg no" value="<?= $carreg; ?>" required>
</div>
<div class="form-group">
<input type="text" name="make" class="form-control" placeholder="Make of car" value="<?= $make; ?>" required>
</div>
<div class="form-group">
<input type="text" name="model" class="form-control" placeholder="Model" value="<?= $model; ?>" required>
</div>
<div class="form-group">
<input type="text" name="price" class="form-control" placeholder="Price" value="<?= $price; ?>" required>
</div>
<div class="form-group">
<input type="hidden" name="oldimage" value="<?= $image1; ?>">
<input type="file" name="image1" class="custom-file">
<img src="<?= $image1; ?>" width="120" class="img-thumbnail">
</div>
<div class="form-group">
<?php if ($update==true){ ?>
<input type="submit" name="update" class="btn btn-success btn-block" value="Update record">
<?php } else { ?>
<input type="submit" name="add" class="btn btn-primary btn-block" value="Add record">
<?php } ?>
</div>
</form>
</div>
</div>
</div>
<?php include 'footer.php'; ?>
I have these table where i want to update the table with additional data...but it only update 1 record even when i pick another column.please help thanks.
// The call to the modal
<a href="#custom-modal" class="btn btn-primary btn-md waves-effect waves-light"
data-animation="fadein" data-id="{{$value->id}}" data-plugin="custommodal" data-overlaySpeed="200" data-overlayColor="#36404a">
<i class="glyphicon glyphicon-refresh "></i> Update
</a>
// method on modal
<form role="form" data-parsley-validate novalidate method="POST" action="{{url('hr/updateRecord/'. $value->id)}}">
// My controller function
public function updateStaff(Request $request)
{
$staff = User::find($request->id);
$staff->salary = $request->salary;
$staff->phone = $request->phone;
$staff->age = $request->age;
$staff->startDate = $request->date;
$staff->office = $request->office;
$staff->save();
Session::flash('message','Successfully Updated '.$request->firstname.'s record');
return redirect('hr/staffdetails');
}
// route
Route::post('/updateRecord/{id}','HrController#updateStaff');
if i try updating record of rope for instance... it's nana's data that would be updated and it's the only record that is updated no matter the name i select
// blade for table
<div class="bottom-table">
<div class="table table-responsive">
<table class="table table-striped table-bordered" id="table">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Position</th>
{{-- <th>Department</th> --}}
<th>Phone number</th>
<th>Office</th>
<th>Age</th>
<th>Start Date</th>
<th>Salary</th>
<th><center>Action</center></th>
</tr>
</thead>
{{ csrf_field() }}
<tbody>
#foreach($staff as $value)
<tr>
<td>{{$value->firstname}}</td>
<td>{{$value->lastname}}</td>
<td>{{$value->position}}</td>
{{-- <td>{{$value->department_id}}</td> --}}
<td>{{$value->phone}}</td>
<td>{{$value->office}}</td>
<td>{{$value->age}}</td>
<td>{{$value->startDate}}</td>
<td>N{{$value->salary}}</td>
<td><center>
<a href="#custom-modal" class="btn btn-primary btn-md waves-effect waves-light"
data-animation="fadein" data-id="{{$value->id}}" data-plugin="custommodal" data-overlaySpeed="200" data-overlayColor="#36404a">
<i class="glyphicon glyphicon-refresh "></i> Update
</a>
<a href="attendance.html" class="show-modal btn btn-info btn-sm" data-id="{{$value->id}}">
<i class="glyphicon glyphicon-time"></i> Attendance
</a>
</center>
</td>
</tr>
#endforeach
</tbody>
</table>
//Modal for update
<div id="custom-modal" class="modal-demo">
<button type="button" class="close" onclick="Custombox.close();">
<span>×</span><span class="sr-only">Close</span>
</button>
<h4 class="custom-modal-title">Update staff report</h4>
<div class="custom-modal-text text-left">
<form role="form" data-parsley-validate novalidate method="POST" action="{{url('hr/updateRecord/'.$value->id)}}">
<input type="hidden" name="_token" value="{{csrf_token()}}"/>
<div class="form-group">
<label for="name">Age</label>
<input type="number" class="form-control" id="name" name="age" required parsley-trigger="change">
</div>
<div class="form-group">
<label for="name">Phone number </label>
<input type="number" class="form-control" id="phone" name="phone" required parsley-trigger="change">
</div>
<div class="form-group">
<label for="name">Office</label>
<input type="text" class="form-control" id="office" name="office" required parsley-trigger="change">
</div>
<div class="form-group">
<label for="name">Salary </label>
<input type="number" class="form-control" id="salary" name="salary" placeholder="" required parsley-trigger="change">
</div>
<div class="form-group">
<label for="assign">Start date</label>
<input type="text" class="form-control" name="date" id="datepicker" placeholder="format yyyy-mm-dd" required parsley-trigger="change">
</div>
<button type="submit" class="btn btn-success waves-effect waves-light">Save</button>
<button type="button" class="btn btn-danger waves-effect waves-light m-l-5">Cancel</button>
</form>
</div>
If you want to mass update
$data = [
'salary' => $request->salary,
'phone' => $request->phone,
'age' => $request->age,
'startDate' => $request->date,
'office' => $request->office,
];
// or $data = $request->all();
User::where('your-condition')->update($data); // it returns updated record counts
Also check in User model:
protected $fillable = ['your columns'];
Documentation https://laravel.com/docs/5.5/eloquent#updates
I am trying to create an edit modal for each row in the database. My page looks like this.
When I click on the edit icon, I open a modal where a user's details can be edited. The modal looks like this.
The modal I intend to show is like this.
My view.php
<div class="box-body">
<table id="example2" class="table table-bordered table-hover">
<thead>
<tr>
<!-- <th></th> -->
<th>Username</th>
<th>Contact</th>
<th>Email</th>
<th>Role Type</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
#foreach ($data as $datas)
<tr>
<td>{{ $datas->username }}</td>
<td>{{ $datas->contact }}</td>
<td>{{ $datas->email }}</td>
<td>Role Type</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#edit-modal">
<i class="fa fa-edit"></I>
</button>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#delete-modal">
<i class="fa fa-trash"></i>
</button>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<div class="modal fade" id="edit-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" align="center"><b>Edit User</b></h4>
</div>
<div class="modal-body">
<form role="form" action="/edit_user">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<div class="box-body">
<div class="form-group">
<label for="exampleInputEmail1">User ID</label>
<input type="text" class="form-control" name="user_id" placeholder="User ID" >
</div>
<div class="form-group">
<label for="exampleInputEmail1">Username</label>
<input type="text" class="form-control" name="username" placeholder="Enter username">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email</label>
<input type="text" class="form-control" name="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Contact</label>
<input type="text" class="form-control" name="contact" placeholder="Enter contact">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Change Password</label>
<input type="password" class="form-control" name="change_password" placeholder="Enter password">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
</div>
How can I achieve the desired output?
Something like this would suffice.
Note: I assume you are using bootstrap 4 for your project, although bootstrap 3 would work too, just tweak it a bit to suit your needs
$(document).ready(function() {
/**
* for showing edit item popup
*/
$(document).on('click', "#edit-item", function() {
$(this).addClass('edit-item-trigger-clicked'); //useful for identifying which trigger was clicked and consequently grab data from the correct row and not the wrong one.
var options = {
'backdrop': 'static'
};
$('#edit-modal').modal(options)
})
// on modal show
$('#edit-modal').on('show.bs.modal', function() {
var el = $(".edit-item-trigger-clicked"); // See how its usefull right here?
var row = el.closest(".data-row");
// get the data
var id = el.data('item-id');
var name = row.children(".name").text();
var description = row.children(".description").text();
// fill the data in the input fields
$("#modal-input-id").val(id);
$("#modal-input-name").val(name);
$("#modal-input-description").val(description);
})
// on modal hide
$('#edit-modal').on('hide.bs.modal', function() {
$('.edit-item-trigger-clicked').removeClass('edit-item-trigger-clicked')
$("#edit-form").trigger("reset");
})
})
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<div class="main-container container-fluid">
<!-- heading -->
<div class="container-fluid">
<div class="row">
<div class="col">
<h1 class="text-primary mr-auto">Example list</h1>
</div>
</div>
</div>
<!-- /heading -->
<!-- table -->
<table class="table table-striped table-bordered" id="myTable" cellspacing="0" width="100%">
<thead class="thead-dark">
<tr>
<th>#</th>
<th> Name</th>
<th> Description</th>
<th> Action</th>
</tr>
</thead>
<tbody>
<tr class="data-row">
<td class="align-middle iteration">1</td>
<td class="align-middle name">Name 1</td>
<td class="align-middle word-break description">Description 1</td>
<td class="align-middle">
<button type="button" class="btn btn-success" id="edit-item" data-item-id="1">edit</button>
</td>
</tr>
<tr class="data-row">
<td class="align-middle iteration">2</td>
<td class="align-middle name">Name 2</td>
<td class="align-middle word-break description">Description 2</td>
<td class="align-middle">
<button type="button" class="btn btn-success" id="edit-item" data-item-id="2">edit</button>
</td>
</tr>
</tbody>
</table>
<!-- /table -->
</div>
<!-- Attachment Modal -->
<div class="modal fade" id="edit-modal" tabindex="-1" role="dialog" aria-labelledby="edit-modal-label" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="edit-modal-label">Edit Data</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="attachment-body-content">
<form id="edit-form" class="form-horizontal" method="POST" action="">
<div class="card text-white bg-dark mb-0">
<div class="card-header">
<h2 class="m-0">Edit</h2>
</div>
<div class="card-body">
<!-- id -->
<div class="form-group">
<label class="col-form-label" for="modal-input-id">Id (just for reference not meant to be shown to the general public) </label>
<input type="text" name="modal-input-id" class="form-control" id="modal-input-id" required>
</div>
<!-- /id -->
<!-- name -->
<div class="form-group">
<label class="col-form-label" for="modal-input-name">Name</label>
<input type="text" name="modal-input-name" class="form-control" id="modal-input-name" required autofocus>
</div>
<!-- /name -->
<!-- description -->
<div class="form-group">
<label class="col-form-label" for="modal-input-description">Email</label>
<input type="text" name="modal-input-description" class="form-control" id="modal-input-description" required>
</div>
<!-- /description -->
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Done</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- /Attachment Modal -->
Suggestion
I would recommend you to include the form in another blade view, render it with all the relevant data and then return it to the controller then show it in the modal.
You can use the below code just pass the $data to the view and it will populate.
#foreach ($data as $datas)
<div class="modal fade" id="edit-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title" align="center"><b>Edit User</b></h4>
</div>
<div class="modal-body">
<form role="form" action="/edit_user">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<div class="box-body">
<div class="form-group">
<label for="exampleInputEmail1">User ID</label>
<input type="text" class="form-control" name="user_id" placeholder="User ID" value="{{$datas->user_id}}">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Username</label>
<input type="text" class="form-control" name="username" placeholder="Enter username" value="{{$datas->username}}">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email</label>
<input type="text" class="form-control" name="email" placeholder="Enter email" value="{{$datas->email}}">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Contact</label>
<input type="text" class="form-control" name="contact" placeholder="Enter contact" value="{{$datas->contact}}">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Change Password</label>
<input type="password" class="form-control" name="change_password" placeholder="Enter password">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
</div>
#endforeach
Easy and simple method.
Simply ensure your data-target and id values are dynamically changing with respect to the individual rows, in this case fix the modal box code into the loop that it takes the values dynamically.
So since you are using Laravel you could do this:
#foreach($rows as $row)
<em class="fa fa-2x fa-edit mr-1"></em>
<div id="myEditModal{{ $row->id }}" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
....
#endforeach
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