|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* rmarchiv.tk |
|
5
|
|
|
* (c) 2016-2017 by Marcel 'ryg' Hering |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace App\Http\Controllers; |
|
9
|
|
|
|
|
10
|
|
|
use Carbon\Carbon; |
|
11
|
|
|
use App\Models\User; |
|
12
|
|
|
use Illuminate\Http\Request; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class UserCreditsController. |
|
16
|
|
|
*/ |
|
17
|
|
|
class UserCreditsController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Store usercredits to the database. |
|
21
|
|
|
* |
|
22
|
|
|
* @param Request $request |
|
23
|
|
|
* @param $id - game_id |
|
24
|
|
|
* |
|
25
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
26
|
|
|
*/ |
|
27
|
|
|
public function store(Request $request, $id) |
|
28
|
|
|
{ |
|
29
|
|
|
if (\Auth::check()) { |
|
30
|
|
|
$this->validate($request, [ |
|
31
|
|
|
'user' => 'required', |
|
32
|
|
|
'credit' => 'required|not_in:0', |
|
33
|
|
|
]); |
|
34
|
|
|
|
|
35
|
|
|
//Get UserID from Username |
|
36
|
|
|
$userid = User::whereName($request->get('user'))->first(); |
|
37
|
|
|
|
|
38
|
|
|
//Check for existing of selected user |
|
39
|
|
|
if ($userid) { |
|
40
|
|
|
//store new usercredit to database |
|
41
|
|
|
\DB::table('user_credits')->insert([ |
|
42
|
|
|
'user_id' => $userid->id, |
|
43
|
|
|
'game_id' => $id, |
|
44
|
|
|
'credit_type_id' => $request->get('credit'), |
|
45
|
|
|
'created_at' => Carbon::now(), |
|
46
|
|
|
]); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return redirect()->action('GameController@edit', [$id]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Deletes user credit in database. |
|
55
|
|
|
* |
|
56
|
|
|
* @param $id |
|
57
|
|
|
* @param $credit_id |
|
58
|
|
|
* |
|
59
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
60
|
|
|
*/ |
|
61
|
|
|
public function destroy($id, $credit_id) |
|
62
|
|
|
{ |
|
63
|
|
|
if (\Auth::check()) { |
|
64
|
|
|
//Delete usercredit from database |
|
65
|
|
|
\DB::table('user_credits') |
|
66
|
|
|
->where('game_id', '=', $id) |
|
67
|
|
|
->where('id', '=', $credit_id) |
|
68
|
|
|
->delete(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return redirect()->action('GameController@edit', [$id]); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|