*/ class IncidentUpdateController extends AbstractApiController { /** * Return all updates on the incident. * * @param \CachetHQ\Cachet\Models\Incident $incident * * @return \Illuminate\Http\JsonResponse */ public function index(Incident $incident) { $updates = $incident->updates()->orderBy('created_at', 'desc'); if ($sortBy = Binput::get('sort')) { $direction = Binput::has('order') && Binput::get('order') == 'desc'; $updates->sort($sortBy, $direction); } $updates = $updates->paginate(Binput::get('per_page', 20)); return $this->paginator($updates, Request::instance()); } /** * Return a single incident update. * * @param \CachetHQ\Cachet\Models\Incident $incident * @param \CachetHQ\Cachet\Models\IncidentUpdate $update * * @return \Illuminate\Http\JsonResponse */ public function show(Incident $incident, IncidentUpdate $update) { return $this->item($update); } /** * Create a new incident update. * * @param \CachetHQ\Cachet\Models\Incident $incident * * @return \Illuminate\Http\JsonResponse */ public function store(Incident $incident) { try { $update = dispatch(new CreateIncidentUpdateCommand( $incident, Binput::get('status'), Binput::get('message'), Auth::user() )); } catch (QueryException $e) { throw new BadRequestHttpException(); } return $this->item($update); } /** * Update an incident update. * * @param \CachetHQ\Cachet\Models\Incident $incident * @param \CachetHQ\Cachet\Models\IncidentUpdate $update * * @return \Illuminate\Http\JsonResponse */ public function update(Incident $incident, IncidentUpdate $update) { try { $update = dispatch(new UpdateIncidentUpdateCommand( $update, Binput::get('status'), Binput::get('message'), Auth::user() )); } catch (QueryException $e) { throw new BadRequestHttpException(); } return $this->item($update); } /** * Create a new incident update. * * @param \CachetHQ\Cachet\Models\Incident $incident * @param \CachetHQ\Cachet\Models\IncidentUpdate $update * * @return \Illuminate\Http\JsonResponse */ public function destroy(Incident $incident, IncidentUpdate $update) { try { dispatch(new RemoveIncidentUpdateCommand($update)); } catch (QueryException $e) { throw new BadRequestHttpException(); } return $this->noContent(); } }