app/Http/Controllers/ToDoItemController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\ToDoItem  $toDoItem
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function editItem(Request $request, $id)
    {
        $inputs = $request->validate([
            'name' => 'string',
            'done' => 'integer',
            'status' => 'string'
        ]);
        $item = ToDoItem::findOrFail($id);
        if (auth()->user()->id !== $item->user->id) {
            return response()->json([
                'error' => 'Unauthorized'
            ], 401); 
        }
        if (isset($inputs['name'])) {
            $item->name = $inputs['name'];
        }
        if (isset($inputs['done'])) {
            $item->done = $inputs['done'];
        }
        if (isset($inputs['status'])) {
            $item->status = $inputs['status'];
        }
        $item->save();
        return response()->json([
            'message' => 'Successfully edited item: ' . $item->name
        ]);  
    }
public function editItem ( Request $ request , $ id ) { $ inputs = $ request -> validate ( [ 'name' => 'string' , 'done' => 'integer' , 'status' => 'string' ] ) ; $ item = ToDoItem :: findOrFail ( $ id ) ; if ( auth ( ) -> user ( ) -> id !== $ item -> user -> id ) { return response ( ) -> json ( [ 'error' => 'Unauthorized' ] , 401 ) ; } if ( isset ( $ inputs [ 'name' ] ) ) { $ item -> name = $ inputs [ 'name' ] ; } if ( isset ( $ inputs [ 'done' ] ) ) { $ item -> done = $ inputs [ 'done' ] ; } if ( isset ( $ inputs [ 'status' ] ) ) { $ item -> status = $ inputs [ 'status' ] ; } $ item -> save ( ) ; return response ( ) -> json ( [ 'message' => 'Successfully edited item: ' . $ item -> name ] ) ; }
Update the specified resource in storage.
Update the specified resource in storage .