Skip to content

Commit d6117a6

Browse files
committed
feat: order info on admin, minor ui issues fix
1 parent cfc639d commit d6117a6

File tree

19 files changed

+628
-161
lines changed

19 files changed

+628
-161
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\Order;
7+
use App\Services\OrderService;
8+
use Illuminate\Http\Request;
9+
10+
class OrderController extends Controller
11+
{
12+
protected OrderService $service;
13+
public function __construct(){
14+
$this->service = new OrderService;
15+
}
16+
public function index(Request $request){
17+
$orders = $this->service->getPaginatedItems($request->all());
18+
return view('admin.orders.index', compact('orders'));
19+
}
20+
}

app/Http/Controllers/Frontend/DashboardController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,5 @@ public function index()
4444
public function transactions(){
4545
$transactions = Transaction::where('user_id', auth()->id())->paginate(10);
4646
return view('frontend.dashboard.transactions', compact('transactions'));
47-
4847
}
4948
}

app/Models/Order.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
namespace App\Models;
44

5+
use App\Traits\Searchable;
56
use Illuminate\Database\Eloquent\Model;
67
use Illuminate\Database\Eloquent\Relations\HasMany;
78
use Illuminate\Database\Eloquent\Relations\HasOne;
89

910
class Order extends Model
1011
{
12+
use Searchable;
13+
protected array $searchable = [
14+
'id',
15+
'order_number',
16+
'payment_gateway',
17+
];
1118
public $guarded = [];
1219
public function items(): HasMany
1320
{

app/Providers/AppServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ public function register(): void
2424
public function boot(): void
2525
{
2626
Blade::component('admin.components.modal', 'modal');
27+
Blade::component('frontend.partials.sidebar', 'sidebar');
2728
}
2829
}

app/Services/OrderService.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Services;
4+
5+
use App\Models\Crud;
6+
use App\Models\Menu;
7+
use App\Models\Order;
8+
9+
class OrderService
10+
{
11+
public function getPaginatedItems($params){
12+
$query = Order::with([
13+
'items.product',
14+
'transaction:id,order_id,transaction_id' // include order_id for the relation to work
15+
]);
16+
$searchQuery = $params['q'] ?? null;
17+
$limit = $params['limit'] ?? config('app.pagination.limit');
18+
$query->when($searchQuery, fn($q) => $q->search($searchQuery));
19+
$orders = $query->orderBy('created_at', 'desc')->paginate($limit);
20+
$orders->appends($params);
21+
return $orders;
22+
}
23+
}

app/Traits/Searchable.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace App\Traits;
3+
4+
trait Searchable
5+
{
6+
public function scopeSearch($query, ?string $term)
7+
{
8+
if (!$term || !property_exists($this, 'searchable') || empty($this->searchable)) {
9+
return $query;
10+
}
11+
12+
return $query->where(function ($q) use ($term) {
13+
foreach ($this->searchable as $field) {
14+
$q->orWhere($field, 'like', "%{$term}%");
15+
}
16+
});
17+
}
18+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
@extends('admin.layouts.app')
2+
@section('title', 'Category Create')
3+
@section('content')
4+
<!-- Page header -->
5+
<div class="page-header d-print-none">
6+
<div class="container-xl">
7+
<div class="row g-2 align-items-center">
8+
<div class="col">
9+
<!-- Page pre-title -->
10+
{{-- <div class="page-pretitle">
11+
Overview
12+
</div> --}}
13+
<h2 class="page-title">
14+
Category
15+
</h2>
16+
</div>
17+
<!-- Page title actions -->
18+
<div class="col-auto ms-auto d-print-none">
19+
<div class="btn-list">
20+
<a href="{{ route('admin.products.categories.index') }}" class="btn btn-danger">
21+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-chevron-left"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M15 6l-6 6l6 6" /></svg>
22+
Back
23+
</a>
24+
</div>
25+
</div>
26+
</div>
27+
</div>
28+
</div>
29+
<div class="page-body">
30+
<div class="container-xl">
31+
<div class="row row-deck row-cards">
32+
<div class="col-12">
33+
<div class="card">
34+
<form action="{{ route('admin.products.categories.store') }}" method="post">
35+
@csrf
36+
<div class="card-header">
37+
<h3 class="card-title">Create new category</h3>
38+
</div>
39+
<div class="card-body">
40+
<div class="mb-3 row">
41+
<label class="col-3 col-form-label required">Category Name</label>
42+
<div class="col">
43+
<input type="text" class="form-control" aria-describedby="emailHelp"
44+
placeholder="Category Name" name="title" value="{{ old('title') }}">
45+
<small class="form-hint">
46+
@error('title')
47+
<div class="text-danger mt-2">{{ $message }}</div>
48+
@enderror
49+
</small>
50+
</div>
51+
</div>
52+
</div>
53+
<div class="card-footer text-end">
54+
<button type="submit" class="btn btn-primary">Submit</button>
55+
</div>
56+
</form>
57+
</div>
58+
</div>
59+
</div>
60+
</div>
61+
</div>
62+
63+
@endsection
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
@extends('admin.layouts.app')
2+
@section('title', 'Category Edit')
3+
@section('content')
4+
<!-- Page header -->
5+
<div class="page-header d-print-none">
6+
<div class="container-xl">
7+
<div class="row g-2 align-items-center">
8+
<div class="col">
9+
<!-- Page pre-title -->
10+
{{-- <div class="page-pretitle">
11+
Overview
12+
</div> --}}
13+
<h2 class="page-title">
14+
Products
15+
</h2>
16+
</div>
17+
<!-- Page title actions -->
18+
<div class="col-auto ms-auto d-print-none">
19+
<div class="btn-list">
20+
<a href="{{ route('admin.products.categories.index') }}" class="btn btn-danger">
21+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-chevron-left"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M15 6l-6 6l6 6" /></svg>
22+
Back
23+
</a>
24+
</div>
25+
</div>
26+
</div>
27+
</div>
28+
</div>
29+
<div class="page-body">
30+
<div class="container-xl">
31+
<div class="row row-deck row-cards">
32+
<div class="col-12">
33+
<form class="card" action="{{ route('admin.products.categories.update', $category->id) }}" method="post">
34+
@csrf
35+
@method('PUT')
36+
<div class="card-header">
37+
<h3 class="card-title">Edit form</h3>
38+
</div>
39+
<div class="card-body">
40+
<div class="mb-3 row">
41+
<label class="col-3 col-form-label required">Category Name</label>
42+
<div class="col">
43+
<input type="text" class="form-control"
44+
placeholder="Product Name" name="title" value="{{ $category->title }}">
45+
<small class="form-hint">
46+
@error('title')
47+
<div class="text-danger mt-2">{{ $message }}</div>
48+
@enderror
49+
</small>
50+
</div>
51+
</div>
52+
</div>
53+
<div class="card-footer text-end">
54+
<button type="submit" class="btn btn-primary">Submit</button>
55+
</div>
56+
</form>
57+
</div>
58+
</div>
59+
</div>
60+
</div>
61+
62+
@endsection
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
@extends('admin.layouts.app')
2+
@section('title', 'Category List')
3+
@section('content')
4+
<!-- Page header -->
5+
<div class="page-header d-print-none">
6+
<div class="container-xl">
7+
<div class="row g-2 align-items-center">
8+
<div class="col">
9+
<!-- Page pre-title -->
10+
{{-- <div class="page-pretitle">
11+
Overview
12+
</div> --}}
13+
<h2 class="page-title">
14+
Orders
15+
</h2>
16+
</div>
17+
<!-- Page title actions -->
18+
<div class="col-auto ms-auto d-print-none">
19+
<div class="btn-list">
20+
<a href="{{ route('admin.products.categories.create') }}" class="btn btn-primary">
21+
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24"
22+
viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
23+
stroke-linecap="round" stroke-linejoin="round">
24+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
25+
<path d="M12 5l0 14" />
26+
<path d="M5 12l14 0" />
27+
</svg>
28+
Create new order
29+
</a>
30+
{{-- <button data-route="{{ route('admin.categories.bulk_delete') }}" type="button" id="bulk-delete-btn" class="btn btn-danger" disabled>Delete Selected</button> --}}
31+
</div>
32+
</div>
33+
</div>
34+
</div>
35+
</div>
36+
<div class="page-body">
37+
<div class="container-xl">
38+
<div class="row row-deck row-cards">
39+
<div class="col-12">
40+
<div class="card">
41+
<div class="card-body border-bottom py-3">
42+
43+
<div class="d-flex">
44+
<div class="text-secondary">
45+
Show
46+
<div class="mx-2 d-inline-block">
47+
<select name="limit" onchange="updateData(this)" data-route="{{ route('admin.orders.index') }}">
48+
<option value="5" @selected((request()->limit ?? 10) == 5)>5</option>
49+
<option value="10" @selected((request()->limit ?? 10) == 10)>10</option>
50+
<option value="20" @selected((request()->limit ?? 10) == 20)>20</option>
51+
</select>
52+
</div>
53+
items
54+
</div>
55+
<div class="ms-auto text-secondary">
56+
Search:
57+
<div class="ms-2 d-inline-block">
58+
<form action="">
59+
<input type="text" class="form-control form-control-sm" aria-label="Search Categories" name="q" value="{{ request()->q }}" placeholder="ID, Order No., Gateway....">
60+
<input type="hidden" name="limit" id="limitInput" value="{{ request()->limit }}">
61+
</form>
62+
</div>
63+
</div>
64+
</div>
65+
66+
</div>
67+
<div class="table-responsive">
68+
<table class="table card-table table-vcenter text-nowrap datatable">
69+
<thead>
70+
<tr>
71+
<th class="w-1"><input class="form-check-input m-0 align-middle" id="select-all-items" type="checkbox" aria-label="Select all invoices"></th>
72+
<th class="w-1">ID
73+
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-sm icon-thick" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 15l6 -6l6 6" /></svg>
74+
</th>
75+
<th>Order No.</th>
76+
{{-- <th>Trx ID</th> --}}
77+
<th>Currency</th>
78+
<th>Gateway</th>
79+
<th>Items</th>
80+
<th>Total</th>
81+
<th>Created at</th>
82+
<th></th>
83+
</tr>
84+
</thead>
85+
<tbody>
86+
@foreach ($orders as $order)
87+
<tr>
88+
<td><input class="form-check-input m-0 align-middle selected-item" type="checkbox" value="{{ $order->id }}" aria-label="Select invoice"></td>
89+
<td><span class="text-secondary">{{ $order->id }}</span></td>
90+
<td><a href="{{ route('admin.orders.show', $order->id) }}" class="text-reset" tabindex="-1">{{ $order->order_number }}</a></td>
91+
{{-- <td>{{ $order->transaction->transaction_id }}</td> --}}
92+
<td>{{ $order->currency }}</td>
93+
<td>{{ $order->payment_gateway }}</td>
94+
<td>
95+
<table class="table border">
96+
<tbody>
97+
@foreach ($order->items as $item)
98+
<tr>
99+
<td class="border">{{ $item->quantity ?? 1 }} x {{ $item->product->title }}</td>
100+
<td class="border">{{ number_format($item->price ?? 0, 2) }}</td>
101+
</tr>
102+
@endforeach
103+
</tbody>
104+
</table>
105+
</td>
106+
<td>{{ $order->total }}</td>
107+
<td>{{ $order->created_at->diffForHumans() }}</td>
108+
<td class="text-end">
109+
<span class="dropdown">
110+
<button class="btn dropdown-toggle align-text-top" data-bs-boundary="viewport" data-bs-toggle="dropdown">Actions</button>
111+
<div class="dropdown-menu dropdown-menu-end">
112+
<a class="dropdown-item" href="{{ route('admin.orders.edit', $order->id) }}">
113+
Edit
114+
</a>
115+
<form onsubmit="return confirmDelete(event, this)"
116+
action="{{ route('admin.orders.destroy', $order->id) }}"
117+
method="post">
118+
@csrf
119+
@method('delete')
120+
<button type="submit" class="text-danger dropdown-item delete-btn">Delete</button>
121+
</form>
122+
</div>
123+
</span>
124+
</td>
125+
</tr>
126+
@endforeach
127+
</tbody>
128+
</table>
129+
</div>
130+
<div class="card-footer">
131+
{{ $orders->links('pagination::bootstrap-5') }}
132+
</div>
133+
</div>
134+
</div>
135+
</div>
136+
</div>
137+
</div>
138+
@endsection
139+
140+

0 commit comments

Comments
 (0)