"Updated MainController, OrderItem model, adminheader, footer, header, and orders blade files with changes to myOrders function, datatables, and modal implementation."

This commit is contained in:
UronShrestha 2024-07-15 11:23:50 +05:45
parent f171e49b3f
commit d8e17eef70
6 changed files with 179 additions and 98 deletions

View File

@ -214,15 +214,49 @@ class MainController extends Controller
} }
// public function myOrders()
// {
// if (session()->has('id')) {
// $orders = Order::where('customerId', session()->get('id'))->get();
// // dd($orders);
// $items = DB::table('products')
// ->join('order_items', 'order_items.productId', '=', 'products.id')
// ->select('products.name', 'products.picture', 'products.*')
// ->get();
// return view('orders', compact('orders', 'items'));
// }
// return view('login');
// }
//old myOrders
// public function myOrders()
// {
// if (session()->has('id')) {
// $orders = Order::where('customerId', session()->get('id'))->get();
// $items = DB::table('products')
// ->join('order_items', 'order_items.productId', '=', 'products.id')
// ->select('products.name', 'products.picture', 'products.*', 'order_items.orderId')
// ->get();
// return view('orders', compact('orders', 'items'));
// }
// return view('login');
// }
//new myOrders
public function myOrders() public function myOrders()
{ {
if (session()->has('id')) { if (session()->has('id')) {
$orders = Order::where('customerId', session()->get('id'))->get(); $orders = Order::where('customerId', session()->get('id'))->get();
$items = DB::table('products') $items = DB::table('products')
->join('order_items', 'order_items.productId', '=', 'products.id') ->join('order_items', 'order_items.productId', '=', 'products.id')
->select('products.name', 'products.picture', 'products.*') ->select('products.name', 'products.picture', 'order_items.*')
->get(); ->get();
return view('orders', compact('orders', 'items')); return view('orders', compact('orders', 'items'));
@ -232,6 +266,8 @@ class MainController extends Controller
} }
public function profile() public function profile()
{ {
if (session()->get('type') == 'Customer') { if (session()->get('type') == 'Customer') {

View File

@ -8,4 +8,5 @@ use Illuminate\Database\Eloquent\Model;
class OrderItem extends Model class OrderItem extends Model
{ {
use HasFactory; use HasFactory;
} }

View File

@ -31,7 +31,7 @@
<!-- endinject --> <!-- endinject -->
<link rel="shortcut icon" href="Dashboard/images/favicon.png" /> <link rel="shortcut icon" href="Dashboard/images/favicon.png" />
<!-- datatables -->
<!-- DataTables CSS --> <!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.4/css/dataTables.bootstrap4.min.css"> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.4/css/dataTables.bootstrap4.min.css">

View File

@ -107,13 +107,14 @@
{{-- Datatables script --}} <!-- datatables-->
<script src="//cdn.datatables.net/2.0.8/js/dataTables.min.js"></script> <script src="Dashboard/js/jquery.dataTables.min.js"></script>
<script> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$('#myTable').DataTable(); $('.table').DataTable();
}); });
</script> </script>
<!-- end datatables-->
<script> <script>
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {

View File

@ -35,15 +35,15 @@
{{-- <link rel="stylesheet" type="text/css" {{-- <link rel="stylesheet" type="text/css"
href="https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/assets/css/chat.min.css"> --}} href="https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/assets/css/chat.min.css"> --}}
</head> <!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.4/css/dataTables.bootstrap4.min.css">
<!-- Include the Stripe.js library --> <!-- jQuery -->
<script src="https://js.stripe.com/v3/"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- datatables--> <!-- DataTables JS -->
<link rel="stylesheet" href="//cdn.datatables.net/2.0.8/css/dataTables.dataTables.min.css"> <script type="text/javascript" src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>
{{-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css"> --}} <script type="text/javascript" src="https://cdn.datatables.net/1.11.4/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/2.0.8/css/dataTables.bootstrap5.css">
</head> </head>

View File

@ -1,70 +1,159 @@
<x-header /> <x-header />
<!-- Contact Section Begin --> <!-- Contact Section Begin -->
<section class="contact spad"> <section class="contact spad">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-lg-10 col-md-6 mx-auto">
<div class="col-lg-8 col-md-8 mx-auto">
<div class="section-title"> <div class="section-title">
<h2>My Orders</h2> <h2>My Orders</h2>
</div> </div>
<div class="contact__form"> <div class="table-responsive">
@if (session('success')) <table class="table table-striped table-bordered" id="myTable">
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
@if (session('error'))
<div class="alert alert-danger">
{{ session('error') }}
</div>
@endif
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<table id="myTable" class="table table-striped table-bordered" style="width:100%">
<thead> <thead>
<tr> <tr>
<th>S.No.</th> <th>S.No.</th>
<th>Name</th> <th>Name</th>
<th>Address</th> <th>Address</th>
{{-- <th>Description</th> --}}
<th>Phone</th> <th>Phone</th>
<th>Status</th> <th>Status</th>
<th>Order Date</th> <th>Order Date</th>
<th>Total Bill</th> <th>Total Bill</th>
<th>View Products</th> <th>View Products</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach ($orders as $order) @php
$i = 0;
@endphp
@foreach ($orders as $item)
@php
$i++;
@endphp
<tr> <tr>
<td>{{ $loop->iteration }}</td> <td>{{ $i }}</td>
<td>{{ $order->name }}</td> <td>{{ $item->name }}</td>
<td>{{ $order->address }}</td> <td>{{ $item->address }}</td>
<td>{{ $order->phone }}</td> {{-- <td>{{ $item->description }}</td> --}}
<td>{{ $order->status }}</td> <td>{{ $item->phone }}</td>
<td>{{ $order->created_at }}</td> <td>{{ $item->status }}</td>
<td>{{ $order->bill }}</td> <td>{{ $item->created_at }}</td>
<td>{{ $item->bill }}</td>
<td> <td>
<!-- Button trigger modal --> <!-- Button to Open the Modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" <button type="button" class="btn btn-primary" data-toggle="modal"
data-bs-target="#viewProductsModal{{ $order->id }}"> data-target="#myModal{{ $i }}">
View View Products
</button> </button>
<!-- The Modal -->
<div class="modal" id="myModal{{ $i }}">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">All Products</h4>
<button type="button" class="close"
data-dismiss="modal">&times;</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<table class="table">
<thead>
<tr>
<th> Name</th>
<th> Picture</th>
<th> Quantity</th>
<th> Price</th>
<th> Total</th>
</thead>
{{-- old tbody --}}
{{-- <tbody>
@foreach ($items as $product)
@if ($product->order_id == $item->id)
<tr>
<td>{{ $product->name }}</td>
<td><img src="{{ asset('uploads/products/' . $product->picture) }}"
alt="" width= "100px"
height="100px"></td>
<td>{{ $product->quantity }}</td>
<td>{{ $product->price }}</td>
<td>{{ $product->price * $product->quantity }}
</td>
</tr>
@endif
@endforeach
</tbody> --}}
{{-- new tbody --}}
<tbody>
@foreach ($items as $product)
@if ($item->id == $product->orderId)
<tr>
<td>{{ $product->name }}</td>
<td><img src="{{ url::asset('uploads/products/' . $product->picture) }}"
class="img-fluid rounded-circle"
alt="" width= "100px"
height="100px"></td>
<td>{{ $product->quantity }}</td>
<td>{{ $product->price }}</td>
<td>{{ $product->price * $product->quantity }}
</td>
</tr>
@endif
@endforeach
</tbody>
<tfoot>
<tr>
<td colspan="4" style="text-align: center;">
<strong>Sub Total</strong>
</td>
<td><strong>{{ $item->bill }}</strong></td>
</tr>
</tfoot>
</table>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger"
data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</td> </td>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
</div> </div>
@ -72,52 +161,6 @@
</section> </section>
<!-- Contact Section End --> <!-- Contact Section End -->
<!-- Modal Begin -->
@foreach ($orders as $order)
<div class="modal fade" id="viewProductsModal{{ $order->id }}" tabindex="-1"
aria-labelledby="exampleModalLabel{{ $order->id }}" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel{{ $order->id }}">All Products</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<table class="table table-bordered">
<thead>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
@foreach ($items as $product)
@if ($product->order_id == $order->id)
<tr>
<td><img src="{{ url::to('uploads/products/' . $product->picture) }}"
width="100px" alt="">{{ $product->name }}</td>
<td>{{ $product->quantity }}</td>
<td>{{ $product->price }}</td>
<td>{{ $product->price * $product->quantity }}</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
{{-- <button type="button" class="btn btn-primary">Save changes</button> --}}
</div>
</div>
</div>
</div>
@endforeach
<!-- Modal End -->
<!-- Footer Section Begin --> <!-- Footer Section Begin -->
<x-footer /> <x-footer />
<!-- Footer Section End --> <!-- Footer Section End -->