-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatchController.php
65 lines (55 loc) · 2.06 KB
/
PatchController.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
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Client;
use App\Patch;
use App\Notes;
class PatchController extends Controller
{
public function getPatches(){
$patch = Patch::with('notes')->orderBy('id', 'DESC')->get();
return response()->json($patch);
}
public function AddPatch(Request $request)
{
$input = $request->input();
$patch = $input['patch'];
$title = $input['title'];
$description = $input['desc'];
$patch_date = $input['patch_date'];
try {
$patch = Patch::firstOrNew(['patch' => $patch]);
$patch->patch = (string)$patch;
$patch->title = (string)$title;
$patch->description = (string)$description;
$patch->patch_date = (string)$patch_date;
$patch->save();
return Controller::filed("Patch has been added successfully", 200);
} catch (BadResponseException $e) {
return Controller::filed($e->getResponse()->getReasonPhrase(), $e->getResponse()->getStatusCode());
}
}
public function AddNote(Request $request)
{
$input = $request->input();
$title = $input['title'];
$description = $input['description'];
$type = $input['type'];
$rune_id = $input['rune_id'];
$patch_id = $input['patch_id'];
try {
$patch = Notes::firstOrNew(['rune_id' => $rune_id],['patch_id' => $patch_id]);
$patch->title = (string)$title;
$patch->description = (string)$description;
$patch->type = (string)$type;
$patch->rune_id = (string)$rune_id;
$patch->patch_id = (string)$patch_id;
$patch->save();
return Controller::filed("Note has been added successfully", 200);
} catch (BadResponseException $e) {
return Controller::filed($e->getResponse()->getReasonPhrase(), $e->getResponse()->getStatusCode());
}
}
}