Passed
Push — dev6 ( edb7de...3fa4bc )
by Ron
15:53
created

CustomerController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 10
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

54
    public function show(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

66
    public function edit(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

78
    public function update(Request $request, /** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

78
    public function update(/** @scrutinizer ignore-unused */ Request $request, $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

89
    public function destroy(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90 1
    {
91 1
        //
92 1
    }
93
}
94