-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackersController.php
executable file
·111 lines (96 loc) · 3 KB
/
BackersController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace ActivismeBE\Http\Controllers;
use ActivismeBE\Finance;
use ActivismeBE\Http\Requests\Backersvalidator;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
/**
* BackersController
*
* @package ActivismeBE\Http\Controllers
*/
class BackersController extends Controller
{
/**
* BackersController Constructor.
*
* @return void
*/
public function __construct()
{
$this->middleware('lang');
$this->middleware('role:Admin');
$this->middleware('banned');
}
/**
* Transaction index for the system.
*
* @param App|Finance $finance
* @return \Illuminate\Http\Response
*/
public function index(Finance $finance)
{
$data['allTransactions'] = $finance->paginate(25);
$data['vredesCaravan'] = $finance->where('finance_plan', 'vredescaravan')->paginate(25);
$data['activisme'] = $finance->where('finance_plan', 'activisme')->paginate(25);
$data['income'] = $finance->where('type', 'inkomsten')->sum('amount');
$data['outcome'] = $finance->where('type', 'uitgaven')->sum('amount');
return view('backers.index', $data);
}
/**
* Create view for a new transaction.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('backers.create');
}
public function showTransaction($id)
{
try {
$data['transaction'] = Finance::findOrFail($id);
return view('backers.show', $data);
} catch (ModelNotFoundException $exception) {
flash('Wij konden de transactie niet vinden in het systeem.')->error();
return redirect()->route('backers');
}
}
/**
* Store a transaction inthe system.
*
* @param Backersvalidator $input
* @param \ActivismeBE\Finance $finance
* @return \Illuminate\Http\Response
*/
public function store(Backersvalidator $input, Finance $finance)
{
$input->merge([
'creator_id' => auth()->user()->id,
'amount' => str_replace(',', '.', $input->amount)
]);
if ($finance->create($input->except(['_token']))) { // Transaction has been stored.
flash('De transactie is opgeslagen in het systeem.');
}
return redirect()->route('backers');
}
/**
* Delete a transaction in the system.
*
* @param integer $id The id for the transaction in the database.
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
try {
$transaction = Finance::findOrFail($id);
if ($transaction->delete()) {
flash('De transactie is verwijderd')->success();
}
return redirect()->route('backers');
} catch (ModelNotFoundException $exception) {
flash('Wij konden de transactie niet vinden.')->error();
return redirect()->route('backers');
}
}
}