Completed
Push — master ( 2f299a...036503 )
by Ron
12:27 queued 05:09
created

CustomerNotesController::store()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 1
nop 1
dl 0
loc 17
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Log;
8
use App\Customers;
9
use App\CustomerNotes;
10
11
class CustomerNotesController extends Controller
12
{
13
    //  Only authorized users have access
14
    public function __construct()
15
    {
16
        $this->middleware('auth');
17
    }
18
    
19
    //  Load the new note form
20
    public function create()
21
    {
22
        return view('customer.form.newNote');
23
    }
24
25
    //  Submit the new customer note
26
    public function store(Request $request)
27
    {
28
        $request->validate([
29
            'custID'      => 'required|numeric',
30
            'subject'     => 'required',
31
            'note'        => 'required'
32
        ]);
33
        
34
        $noteID = CustomerNotes::create([
35
            'cust_id'     => $request->custID,
36
            'user_id'     => Auth::user()->user_id,
37
            'urgent'      => isset($request->urgent) && $request->urgent ? true : false,
38
            'subject'     => $request->subject,
39
            'description' => $request->note
40
        ]);
41
        
42
        Log::info('Customer Note Created for Customer ID-'.$request->custID.' by User ID-'.Auth::user()->user_id.'.  New Note ID-'.$noteID->note_id);
43
    }
44
45
    //  Show all customer notes
46
    public function show($id)
47
    {
48
        $notes = CustomerNotes::where('cust_id', $id)->orderBy('urgent', 'desc')->get();
49
        
50
        return view('customer.notes', [
51
            'notes' => $notes
52
        ]);
53
    }
54
55
    //  Open the Edit Note form
56
    public function edit($id)
57
    {
58
        $note = CustomerNotes::find($id);
59
        
60
        return view('customer.form.editNote', [
61
            'noteID' => $id,
62
            'note'   => $note
63
        ]);
64
    }
65
66
    //  Update a customer note
67
    public function update(Request $request, $id)
68
    {
69
        $request->validate([
70
            'subject'     => 'required',
71
            'description' => 'required'
72
        ]);
73
        
74
        CustomerNotes::find($id)->update(
75
        [
76
            'urgent'      => isset($request->urgent) && $request->urgent ? true : false,
77
            'subject'     => $request->subject,
78
            'description' => $request->description
79
        ]);
80
        
81
        Log::info('Customer Note ID-'.$id.' updated by User ID-'.Auth::user()->user_id);
82
    }
83
84
    /**
85
     * Remove the specified resource from storage.
86
     *
87
     * @param  int  $id
88
     * @return \Illuminate\Http\Response
89
     */
90
    public function destroy($id)
91
    {
92
        //
93
    }
94
}
95