BillReceiveController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 125
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A destroy() 0 8 1
A __construct() 0 3 1
A store() 0 14 1
A index() 0 4 1
A toggle() 0 10 1
A edit() 0 5 1
A create() 0 4 1
A update() 0 15 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Session;
7
8
class BillReceiveController extends Controller
9
{
10
    /**
11
     * Create a new controller instance.
12
     *
13
     * @return void
14
     */
15
    public function __construct()
16
    {
17
        $this->middleware('auth');
18
    }
19
    
20
    /**
21
     * Display a listing of the resource.
22
     *
23
     * @return \Illuminate\Http\Response
24
     */
25
    public function index()
26
    {
27
        $bill_receives = auth()->user()->bill_receives()->orderBy('name', 'asc')->paginate(10);
28
        return view('bill_receives.index', compact('bill_receives'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('bill_receiv...mpact('bill_receives')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
29
    }
30
31
    /**
32
     * Show the form for creating a new resource.
33
     *
34
     * @return \Illuminate\Http\Response
35
     */
36
    public function create()
37
    {
38
        $categories = auth()->user()->categories()->get();
39
        return view('bill_receives.create', compact('categories'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('bill_receiv... compact('categories')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
40
    }
41
42
    /**
43
     * Store a newly created resource in storage.
44
     *
45
     * @param  \Illuminate\Http\Request  $request
46
     * @return \Illuminate\Http\Response
47
     */
48
    public function store(Request $request)
49
    {
50
        $this->validate($request, [
51
            'category_id' => 'required',
52
            'date_launch' => 'required|date',
53
            'name' => 'required|min:3|max:255',
54
            'value' => 'required|numeric'
55
        ]);
56
        
57
        auth()->user()->bill_receives()->create($request->all());
58
59
        Session::flash('success', 'Conta a receber criada com sucesso');
60
61
        return redirect()->route('bill_receives.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route('bill_receives.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
62
    }
63
64
    /**
65
     * Show the form for editing the specified resource.
66
     *
67
     * @param  int  $id
68
     * @return \Illuminate\Http\Response
69
     */
70
    public function edit($id)
71
    {
72
        $categories = auth()->user()->categories()->get();
73
        $bill_receive = auth()->user()->bill_receives()->findOrFail($id);
74
        return view('bill_receives.edit', compact('bill_receive','categories'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('bill_receiv...eceive', 'categories')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
75
    }
76
77
    /**
78
     * Update the specified resource in storage.
79
     *
80
     * @param  \Illuminate\Http\Request  $request
81
     * @param  int  $id
82
     * @return \Illuminate\Http\Response
83
     */
84
    public function update(Request $request, $id)
85
    {
86
        $this->validate($request, [
87
            'category_id' => 'required',
88
            'date_launch' => 'required|date',
89
            'name' => 'required|min:3|max:255',
90
            'value' => 'required|numeric'
91
        ]);
92
93
        $bill_receive = auth()->user()->bill_receives()->findOrFail($id);
94
        $bill_receive->update($request->all());
95
                
96
        Session::flash('success', 'Conta a receber atualizada com sucesso');
97
98
        return redirect()->route('bill_receives.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route('bill_receives.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
99
    }
100
101
    /**
102
     * Remove the specified resource from storage.
103
     *
104
     * @param  int  $id
105
     * @return \Illuminate\Http\Response
106
     */
107
    public function destroy($id)
108
    {
109
        $bill_receive = auth()->user()->bill_receives()->findOrFail($id);        
110
        $bill_receive->delete();
111
112
        Session::flash('success', 'Conta a receber deletada com sucesso');
113
114
        return redirect()->back();
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
115
    }
116
117
    /**
118
     * Update the specified resource in storage.
119
     *
120
     * @param  \Illuminate\Http\Request  $request
121
     * @return \Illuminate\Http\Response
122
     */
123
    public function toggle(Request $request)
124
    {
125
        $this->validate($request, [
126
            "id" => "exists:bill_receives,id"
127
        ]);
128
129
        $bill_receive = auth()->user()->bill_receives()->findOrFail($request->id);
130
        $bill_receive->update(['status' => !$bill_receive->status]);
131
                
132
        return response()->json(['status' => 'success', 'message' => 'Conta a receber atualizada com sucesso']);
0 ignored issues
show
Bug Best Practice introduced by
The expression return response()->json(...ualizada com sucesso')) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
133
    }
134
}
135