toDo change order

This commit is contained in:
2020-04-24 23:03:12 +02:00
parent 0c89550dfe
commit 3dc00ec768
4 changed files with 46 additions and 23 deletions

View File

@@ -45,11 +45,25 @@ class ToDoController extends Controller
return response([], 204);
}
public function changeOrder(ToDoList $toDoList, ToDo $toDo)
{
$this->authorize('update', $toDoList);
$toDoChanged = $toDoList->toDos()->where('order', (int) request()['new-order'])->first();
$toDoChanged->update(['order' => (int) $toDo->order]);
$toDo->update(['order' => (int) request()['new-order']]);
return (new ToDoResource($toDo))
->response()
->setStatusCode(200);
}
private function validateData()
{
return request()->validate([
'name' => 'required',
'order' => 'integer|min:1|max:1000000'
'order' => 'integer|min:1|max:1000000',
]);
}
}