Skip to content

Commit

Permalink
update AllProduct
Browse files Browse the repository at this point in the history
  • Loading branch information
Abu-Salah-Musha-Lemon committed Sep 24, 2024
1 parent db14597 commit e9c0a6f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 63 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HomeController extends Controller
public function index()
{
// Fetch the latest products and paginate them
$products = Product::latest()->paginate(10); // This fetches 20 latest products per page
$products = Product::latest()->paginate(9); // This fetches 20 latest products per page
return view('userTemp.home', compact('products')); // Pass the paginated products to the view
}

Expand Down
8 changes: 5 additions & 3 deletions app/Http/Controllers/admin/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
class ProductController extends Controller
{
public function index()
{ $categories = Category::latest()->get();
{
$categories = Category::latest()->get();
$subcategories = Subcategory::latest()->get();
$products = Product::latest()->get(); // Assuming you have a Product model

$products = Product::latest()->paginate(9);
return view('admin.product.allProduct', compact('categories', 'subcategories', 'products'));
}


public function create()
{
Expand Down
105 changes: 46 additions & 59 deletions resources/views/admin/product/allProduct.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,62 @@
<div class="card">
<div class="card-header d-flex align-items-center justify-content-between">
<h5 class="card-header">All Products</h5>
<small class="text-muted float-end"><a href="{{route('product.create')}}" class="btn btn-success"><i
<small class="text-muted float-end"><a href="{{ route('product.create') }}" class="btn btn-success"><i
class="bi bi-cart-plus"></i></a></small>
</div>
<style>
.table-responsive {
margin: 20px; /* Adjust as necessary */
}
</style>

<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="table-responsive">
<table id="dataTable" class="table table-striped table-bordered">
<thead>
<tr class="text-nowrap">
<th>#</th>
<th>Product Name</th>
<th>Product Price</th>
<th>Product Count</th>
<th>Product Image</th>
<th>Actions</th>
</tr>
</thead>
<tbody class="table-border-bottom-0">
@foreach($products as $product)
<tr>
<th scope="row">{{ $loop->iteration }}</th>
<td>{{ $product->product_name }}</td>
<td>${{ number_format($product->product_price, 2) }}</td>
<td>{{ $product->product_quantity }}</td>
<td>
@if($product->product_img)
<img src="{{ asset('products/' . $product->product_img) }}" alt="{{ $product->product_name }}" width="40" height="40">
@else
No product_img
@endif
</td>
<td>
<a href="{{ route('product.edit', $product->id) }}" class="btn btn-outline-primary"><i class="bi bi-pencil-square"></i></a>
<a href="{{ route('product.show', $product->id) }}" class="btn btn-outline-secondary"><i class="bi bi-eye"></i></a>
<form action="{{ route('product.destroy', $product->id) }}" method="get" style="display:inline;">
@csrf
<button type="submit" class="btn btn-outline-danger" onclick="return confirm('Are you sure?')"><i class="bi bi-trash"></i></button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>

<script>
$(document).ready(function () {
initializeDataTable(['Product Name', 'Product Price', 'Product Count']);
});
</script>


<div class="table-responsive" style="margin: 20px;">
<table id="dataTable" class="table table-striped table-bordered">
<thead>
<tr class="text-nowrap">
<th>#</th>
<th>Product Name</th>
<th>Product Price</th>
<th>Product Count</th>
<th>Product Image</th>
<th>Actions</th>
</tr>
</thead>
<tbody class="table-border-bottom-0">
@foreach($products as $product)
<tr>
<th scope="row">{{ $loop->iteration }}</th>
<td>{{ $product->product_name }}</td>
<td>${{ number_format($product->product_price, 2) }}</td>
<td>{{ $product->product_quantity }}</td>
<td>
@if($product->product_img)
<img src="{{ asset('products/' . $product->product_img) }}" alt="{{ $product->product_name }}"
width="40" height="40">
@else
<img src="{{ asset('images/placeholder.png') }}" alt="No Image" width="40" height="40">
@endif
</td>
<td>
<a href="{{ route('product.edit', $product->id) }}" class="btn btn-outline-primary"><i
class="bi bi-pencil-square"></i></a>
<a href="{{ route('product.show', $product->id) }}" class="btn btn-outline-secondary"><i
class="bi bi-eye"></i></a>
<form action="{{ route('product.destroy', $product->id) }}" method="GET" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-outline-danger" onclick="return confirm('Are you sure?')"><i
class="bi bi-trash"></i></button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
{{ $products->links() }}
</div>
</div>
</div>
</div>
@section('script')
<script>
$(document).ready(function () {
initializeDataTable(['Product Name', 'Product Price', 'Product Count']);
});
</script>
@endsection
Expand Down

0 comments on commit e9c0a6f

Please sign in to comment.