/** * Execute the console command. * * @return mixed */ public function handle() { $monitors = Monitor::select('*')->selectRaw('DATE_ADD(pinged_at, INTERVAL allowed_runtime SECOND) as end_time')->where('state', Monitor::STATE_RUNNING)->having('end_time', '<', new Carbon())->get(); /** @var Monitor $monitor */ foreach ($monitors as $monitor) { $monitor->warnings()->create(['type' => Monitor::STATE_LATE]); $monitor->state = Monitor::STATE_LATE; $monitor->save(); } }
/** * Bootstrap any application services. * * @return void */ public function boot() { // Set UUID for Monitors on create Monitor::creating(function (Monitor $monitor) { $monitor->uuid = Uuid::generate(4); }); \Blade::directive('datediff', function ($carbon) { return "<?php echo '<span title=\"'\n .with{$carbon}->format('Y-m-d H:i:s').'\">'.with{$carbon}->diffForHumans().'</span>'; ?>"; }); }
/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { $router->bind('integrations', function ($id) use($router) { $user = \Auth::user(); return Integration::whereUserId($user->id)->whereId($id)->firstOrFail(); }); $router->bind('monitors', function ($uuid) { return Monitor::where('uuid', $uuid)->firstOrFail(); }); parent::boot($router); }
/** * Remove the specified resource from storage. * * @param Monitor $monitor * @return \Illuminate\Http\Response * @internal param int $id */ public function destroy(Monitor $monitor) { $monitor->delete(); return redirect(route('account.monitors.index')); }
public function fail(Request $request, Monitor $monitor) { $monitor->updateState(Monitor::STATE_FAIL); }