Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| OrderTrackingController | |
92.31% |
12 / 13 |
|
50.00% |
1 / 2 |
2.00 | |
0.00% |
0 / 1 |
| show | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| lookup | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\Customer; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Models\Order; |
| 7 | use Illuminate\Http\Request; |
| 8 | use Illuminate\View\View; |
| 9 | |
| 10 | /** |
| 11 | * Public order tracking — no login needed. A guest (or a customer who'd |
| 12 | * rather not sign in) looks their order up by reference number + the phone |
| 13 | * they checked out with, same identity check the thank-you page trusts. |
| 14 | */ |
| 15 | class OrderTrackingController extends Controller |
| 16 | { |
| 17 | public function show(): View |
| 18 | { |
| 19 | return view('website.account.track-order', ['order' => null]); |
| 20 | } |
| 21 | |
| 22 | public function lookup(Request $request): View |
| 23 | { |
| 24 | $data = $request->validate([ |
| 25 | 'order_number' => ['required', 'string'], |
| 26 | 'phone' => ['required', 'string'], |
| 27 | ]); |
| 28 | |
| 29 | $order = Order::with(['details.stock.product', 'customer', 'payment']) |
| 30 | ->where('bar_code', trim($data['order_number'])) |
| 31 | ->whereHas('customer', fn ($q) => $q->where('phone', trim($data['phone']))) |
| 32 | ->first(); |
| 33 | |
| 34 | return view('website.account.track-order', [ |
| 35 | 'order' => $order, |
| 36 | 'searched' => true, |
| 37 | ]); |
| 38 | } |
| 39 | } |