first work on to do orders
This commit is contained in:
@@ -14,6 +14,10 @@ class ToDoController extends Controller
|
||||
{
|
||||
$this->authorize('create', ToDoList::class);
|
||||
|
||||
$lastToDo = $toDoList->toDos()->orderBy('order', 'desc')->first();
|
||||
|
||||
request()['order'] = ($lastToDo) ? $lastToDo->order + 1 : 1;
|
||||
|
||||
$toDo = $toDoList->toDos()->create($this->validateData());
|
||||
|
||||
return (new ToDoResource($toDo))
|
||||
@@ -32,10 +36,20 @@ class ToDoController extends Controller
|
||||
->setStatusCode(200);
|
||||
}
|
||||
|
||||
public function destroy(ToDoList $toDoList, ToDo $toDo)
|
||||
{
|
||||
$this->authorize('delete', $toDoList);
|
||||
|
||||
$toDo->delete();
|
||||
|
||||
return response([], 204);
|
||||
}
|
||||
|
||||
private function validateData()
|
||||
{
|
||||
return request()->validate([
|
||||
'name' => 'required',
|
||||
'order' => 'integer|min:1|max:1000000'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class ToDo extends JsonResource
|
||||
'attributes' => [
|
||||
'data' => [
|
||||
'name' => $this->name,
|
||||
'order' => $this->order,
|
||||
'order' => (int) $this->order,
|
||||
'checked_at' => optional($this->checked_at)->diffForHumans(),
|
||||
'last_updated' => $this->updated_at->diffForHumans(),
|
||||
]
|
||||
|
||||
@@ -16,7 +16,7 @@ class ToDoList extends Model
|
||||
return '/to-do-lists/' . $this->id;
|
||||
}
|
||||
|
||||
public function users(): BelongsTo
|
||||
public function author(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user