Passed
Push — dev6 ( 1762ad...6b002f )
by Ron
08:16
created

CustomerIdController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 0
f 0
dl 0
loc 43
ccs 12
cts 16
cp 0.75
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A edit() 0 6 1
A index() 0 5 1
A update() 0 16 2
1
<?php
2
3
namespace App\Http\Controllers\Customers;
4
5
use Inertia\Inertia;
6
7
use App\Models\Customer;
8
use App\Http\Controllers\Controller;
9
use App\Http\Requests\Customers\CustIdRequest;
10
11
use Illuminate\Support\Facades\Log;
12
use Illuminate\Database\QueryException;
13
14
class CustomerIdController extends Controller
15
{
16
    /**
17
     *  Search parameter to select which ID to change
18
     */
19 2
    public function index()
20
    {
21 2
        $this->authorize('manage', Customer::class);
22
23 1
        return Inertia::render('Customer/changeId');
24
    }
25
26
    /**
27
     *  Show the Change ID Form
28
     */
29 2
    public function edit($id)
30
    {
31 2
        $this->authorize('manage', Customer::class);
32
33 1
        return Inertia::render('Customer/changeIdForm', [
34 1
            'details' => Customer::where('slug', $id)->firstOrFail(),
35
        ]);
36
    }
37
38
    /**
39
     *  Submit the Change ID Form
40
     */
41 1
    public function update(CustIdRequest $request, $id)
42
    {
43 1
        $cust = Customer::findOrFail($id);
44
45
        try{
46 1
            $cust->update($request->only(['cust_id']));
47
        }
48
        catch(QueryException $e)
49
        {
50
            Log::error('Update Customer ID failed');
51
            Log::error($e);
52
            return redirect()->back()->with(['message' => 'Unable to Update Customer ID for linked Customers', 'type' => 'danger']);
53
        }
54
55 1
        Log::channel('cust')->notice('Customer ID has been updated for Customer '.$cust->name.' from '.$id.' to '.$request->cust_id.' by '.$request->user()->username);
56 1
        return redirect()->route('admin.index');
57
    }
58
}
59