A. view.blade.php
<h3>Edit Bags</h3><br/>
<?php $data = DB::table('bags')->where('id', $id)->get(); foreach($data as $d){ $title = $d->title; $address = $d->address; } ?>
<div class="container"> <div class="card" style="padding:10px; background:white"> @if (session('message')) <div class="alert alert-success" id="msg"> {{ session('message') }} </div> @endif <form action="{{route('update_bags')}}" method="post" class="was-validated"> @csrf <input type="hidden" name="id" value="{{$id}}" /> <div class="mb-3 mt-3″> <label for="uname" class="form-label">Title:</label> <input type="text" class="form-control" id="title" placeholder="Enter title" name="title" value="{{$title}}"> <div class="valid-feedback"></div> </div> <div class="mb-3″> <label for="pwd" class="form-label">Address:</label> <textarea type="password" class="form-control" id="pwd" name="address">{{$address}}</textarea> <div class="valid-feedback"></div> </div><br/> <button type="submit" class="btn btn-primary">Submit</button> <a href="{{URL::To('en/admin/shipments/all-bags')}} "><button type="button" class="btn btn-dark">Back</button></a> </form> </div> </div> <script> $(document).ready(function(){ $("#msg").fadeOut(3000); }); </script>
B. Controller.php
function update_bags(Request $req){ $id = $req->id; $title = $req->title; $address = $req->address; DB::table('bags')->where('id', $id)->update([ 'title' => $title, 'address' => $address ]); return back()->with('message','Update Successfully !'); }