|
1
|
|
|
<?php |
|
2
|
|
|
namespace Spatie\UptimeMonitor\Http\Controller; |
|
3
|
|
|
|
|
4
|
|
|
use App\Http\Controllers\Controller; |
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Spatie\UptimeMonitor\Models\Monitor; |
|
7
|
|
|
use Spatie\Url\Url; |
|
8
|
|
|
|
|
9
|
|
|
class MonitorController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Display a listing of the resource. |
|
13
|
|
|
* |
|
14
|
|
|
* @return \Illuminate\Http\Response |
|
15
|
|
|
*/ |
|
16
|
|
|
public function index() |
|
17
|
|
|
{ |
|
18
|
|
|
return Monitor::all(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Store a newly created resource in storage. |
|
23
|
|
|
* |
|
24
|
|
|
* @param \Illuminate\Http\Request $request |
|
25
|
|
|
* @return \Illuminate\Http\Response |
|
26
|
|
|
*/ |
|
27
|
|
|
public function store(Request $request) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->validate($request, config('laravel-uptime-monitor.restAPI.validationRules')); |
|
30
|
|
|
$url = Url::fromString($request->get('url')); |
|
31
|
|
|
Monitor::create([ |
|
32
|
|
|
'url' => trim($url, '/'), |
|
33
|
|
|
'look_for_string' => $request->get('look_for_string') ?? '', |
|
34
|
|
|
'uptime_check_method' => $request->has('look_for_string') ? 'get' : 'head', |
|
35
|
|
|
'certificate_check_enabled' => $url->getScheme() === 'https', |
|
36
|
|
|
'uptime_check_interval_in_minutes' => config('laravel-uptime-monitor.uptime_check.run_interval_in_minutes'), |
|
37
|
|
|
]); |
|
38
|
|
|
return response()->setStatusCode(201); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Display the specified resource. |
|
43
|
|
|
* |
|
44
|
|
|
* @param int $id |
|
45
|
|
|
* @return \Illuminate\Http\Response |
|
46
|
|
|
*/ |
|
47
|
|
|
public function show($id) |
|
48
|
|
|
{ |
|
49
|
|
|
return Monitor::findOrFail($id); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Update the specified resource in storage. |
|
54
|
|
|
* |
|
55
|
|
|
* @param \Illuminate\Http\Request $request |
|
56
|
|
|
* @param int $id |
|
57
|
|
|
* @return \Illuminate\Http\Response |
|
58
|
|
|
*/ |
|
59
|
|
|
public function update(Request $request, $id) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->validate($request, config('laravel-uptime-monitor.restAPI.validationRules')); |
|
62
|
|
|
|
|
63
|
|
|
$monitor = Monitor::findOrFail($id); |
|
64
|
|
|
$look_for_string = ($request->has('look_for_string')) ? $request->get('look_for_string') : $monitor->look_for_string; |
|
65
|
|
|
return $monitor->update(['url' => $request->get('url'), 'look_for_string' => $look_for_string]); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Remove the specified resource from storage. |
|
70
|
|
|
* |
|
71
|
|
|
* @param int $id |
|
72
|
|
|
* @return \Illuminate\Http\Response |
|
73
|
|
|
*/ |
|
74
|
|
|
public function destroy($id) |
|
75
|
|
|
{ |
|
76
|
|
|
$monitor = Monitor::findOrFail($id); |
|
77
|
|
|
return $monitor->delete(); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.