Cachet/src/Http/Controllers/DashAPIController.php

48 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace CachetHQ\Cachet\Http\Controllers;
2015-01-01 15:45:04 +00:00
use CachetHQ\Cachet\Models\Component;
2015-01-01 16:18:24 +00:00
use Exception;
2015-01-02 12:05:50 +00:00
use GrahamCampbell\Binput\Facades\Binput;
2015-01-01 15:45:04 +00:00
use Illuminate\Routing\Controller;
class DashAPIController extends Controller
{
/**
* Updates a component with the entered info.
2014-12-30 18:19:22 +00:00
*
* @param \CachetHQ\Cachet\Models\Component $component
2014-12-30 18:19:22 +00:00
*
2015-01-01 15:45:04 +00:00
* @throws \Exception
*
* @return \CachetHQ\Cachet\Models\Component
*/
public function postUpdateComponent(Component $component)
{
2015-01-02 12:05:50 +00:00
if (!$component->update(Binput::except(['_token']))) {
throw new Exception(trans('dashboard.components.edit.failure'));
}
2015-01-01 15:45:04 +00:00
return $component;
}
2015-01-01 13:40:02 +00:00
/**
* Updates a components ordering.
*
* @return array
*/
public function postUpdateComponentOrder()
{
2015-01-02 12:05:50 +00:00
$componentData = Binput::all();
unset($componentData['component'][0]); // Remove random 0 index.
foreach ($componentData['component'] as $componentId => $order) {
$component = Component::find($componentId);
2015-01-01 15:45:04 +00:00
$component->update(['order' => $order]);
}
return $componentData;
}
}