mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-14 01:24:06 -08:00
39 lines
941 B
PHP
39 lines
941 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\Api;
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use App\Models\CustomFieldset;
|
||
|
|
||
|
class CustomFieldsController extends Controller
|
||
|
{
|
||
|
/**
|
||
|
* Reorder the custom fields within a fieldset
|
||
|
*
|
||
|
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||
|
* @param int $id
|
||
|
* @since [v3.0]
|
||
|
* @return Array
|
||
|
*/
|
||
|
public function postReorder(Request $request, $id)
|
||
|
{
|
||
|
$fieldset = CustomFieldset::find($id);
|
||
|
$fields = array();
|
||
|
$order_array = array();
|
||
|
|
||
|
$items = $request->input('item');
|
||
|
|
||
|
foreach ($items as $order => $field_id) {
|
||
|
$order_array[$field_id] = $order;
|
||
|
}
|
||
|
|
||
|
foreach ($fieldset->fields as $field) {
|
||
|
$fields[$field->id] = ['required' => $field->pivot->required, 'order' => $order_array[$field->id]];
|
||
|
}
|
||
|
|
||
|
return $fieldset->fields()->sync($fields);
|
||
|
|
||
|
}
|
||
|
}
|