1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Customers; |
4
|
|
|
|
5
|
|
|
use App\Events\NewCustomerCreated; |
6
|
|
|
use Inertia\Inertia; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use App\Http\Controllers\Controller; |
9
|
|
|
use App\Http\Requests\Customers\NewCustomerRequest; |
10
|
|
|
use App\Models\Customer; |
11
|
|
|
use App\Models\EquipmentType; |
12
|
|
|
use Illuminate\Support\Str; |
13
|
|
|
|
14
|
|
|
class CustomerController extends Controller |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Search page for finding a customer |
18
|
|
|
*/ |
19
|
|
|
public function index(Request $request) |
20
|
|
|
{ |
21
|
|
|
return Inertia::render('Customers/Index', [ |
22
|
|
|
'create' => $request->user()->can('create', Customer::class), |
23
|
|
|
'equip_types' => EquipmentType::orderBy('cat_id')->get()->pluck('name')->values(), |
24
|
|
|
]); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Show the form for creating a new Customer |
29
|
1 |
|
*/ |
30
|
|
|
public function create() |
31
|
1 |
|
{ |
32
|
1 |
|
$this->authorize('create', Customer::class); |
33
|
1 |
|
return Inertia::render('Customers/Create'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Create a new Customer |
38
|
|
|
*/ |
39
|
|
|
public function store(NewCustomerRequest $request) |
40
|
2 |
|
{ |
41
|
|
|
$cust = $request->toArray(); |
42
|
2 |
|
$cust['slug'] = Str::slug($request->name); |
43
|
1 |
|
$newCust = Customer::create($cust); |
44
|
|
|
|
45
|
|
|
// Log::channel('cust')->info('New Customer - '.$request->name.' created by '.Auth::user()->full_name); |
46
|
|
|
|
47
|
|
|
event(new NewCustomerCreated($newCust)); |
48
|
|
|
return redirect(route('customers.show',$newCust->slug))->with(['message' => 'New Customer Created', 'type' => 'success']); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
1 |
|
/** |
52
|
1 |
|
* Display the Customers Information |
53
|
1 |
|
*/ |
54
|
|
|
public function show($id) |
|
|
|
|
55
|
1 |
|
{ |
56
|
|
|
// |
57
|
1 |
|
return Inertia::render('Customers/Show'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Show the form for editing the specified resource. |
62
|
|
|
* |
63
|
3 |
|
* @param int $id |
64
|
|
|
* @return \Illuminate\Http\Response |
65
|
|
|
*/ |
66
|
3 |
|
public function edit($id) |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
// |
69
|
1 |
|
} |
70
|
1 |
|
|
71
|
|
|
/** |
72
|
|
|
* Update the specified resource in storage. |
73
|
2 |
|
* |
74
|
2 |
|
* @param \Illuminate\Http\Request $request |
75
|
2 |
|
* @param int $id |
76
|
2 |
|
* @return \Illuminate\Http\Response |
77
|
2 |
|
*/ |
78
|
2 |
|
public function update(Request $request, $id) |
|
|
|
|
79
|
2 |
|
{ |
80
|
2 |
|
// |
81
|
2 |
|
} |
82
|
2 |
|
|
83
|
2 |
|
/** |
84
|
2 |
|
* Remove the specified resource from storage. |
85
|
1 |
|
* |
86
|
1 |
|
* @param int $id |
87
|
1 |
|
* @return \Illuminate\Http\Response |
88
|
|
|
*/ |
89
|
1 |
|
public function destroy($id) |
|
|
|
|
90
|
1 |
|
{ |
91
|
1 |
|
// |
92
|
1 |
|
} |
93
|
|
|
} |
94
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.