/** * Run the database seeding. */ public function run() { $defaultMetrics = [['name' => 'Cups of coffee', 'suffix' => 'Cups', 'description' => 'How many cups of coffee we\'ve drank.', 'default_value' => 0, 'calc_type' => 1, 'display_chart' => 1]]; Metric::truncate(); foreach ($defaultMetrics as $metric) { Metric::create($metric); } }
/** * Run the database seeding. */ public function run() { $defaultMetrics = [['name' => 'Demo Metric', 'suffix' => 'rnd', 'description' => 'Random data points.', 'default_value' => 0, 'calc_type' => 1, 'display_chart' => 1]]; Metric::truncate(); foreach ($defaultMetrics as $metric) { Metric::create($metric); } }
/** * Create a new metric. * * @return \Illuminate\Http\JsonResponse */ public function postMetrics() { try { $metric = Metric::create(Binput::all()); } catch (Exception $e) { throw new BadRequestHttpException(); } return $this->item($metric); }
/** * Creates a new metric. * * @return \Illuminate\Http\RedirectResponse */ public function createMetricAction() { try { Metric::create(Binput::get('metric')); } catch (ValidationException $e) { return Redirect::route('dashboard.metrics.add')->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.metrics.add.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('dashboard.metrics.add')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.add.success'))); }
/** * Creates a new metric. * * @return \Illuminate\Http\RedirectResponse */ public function createMetricAction() { $metricData = Binput::get('metric'); $metric = Metric::create($metricData); if (!$metric->isValid()) { return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.metrics.add.failure')))->with('errors', $metric->getErrors()); } $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.add.success')); return Redirect::back()->with('success', $successMsg); }
/** * Handle the add metric command. * * @param \CachetHQ\Cachet\Bus\Commands\Metric\AddMetricCommand $command * * @return \CachetHQ\Cachet\Models\Metric */ public function handle(AddMetricCommand $command) { $metric = Metric::create(['name' => $command->name, 'suffix' => $command->suffix, 'description' => $command->description, 'default_value' => $command->default_value, 'calc_type' => $command->calc_type, 'display_chart' => $command->display_chart, 'places' => $command->places, 'default_view' => $command->default_view]); event(new MetricWasAddedEvent($metric)); return $metric; }