app/Http/Controllers/ToDoItemController.php
/**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\ToDoItem  $toDoItem
     * @return \Illuminate\Http\Response
     */
Remove the specified resource from storage.
Remove the specified resource from storage .
public function destroy($id)
    {
        $item = ToDoItem::findOrFail($id);
        if (auth()->user()->id !== $item->user->id) {
            return response()->json([
                'error' => 'Unauthorized'
            ], 401); 
        }
        $name = $item->name;
        $item->delete(); 
        return response()->json([
            'message' => 'Successfully deleted item: ' . $name
        ]);  
    }
public function destroy ( $ id ) { $ item = ToDoItem :: findOrFail ( $ id ) ; if ( auth ( ) -> user ( ) -> id !== $ item -> user -> id ) { return response ( ) -> json ( [ 'error' => 'Unauthorized' ] , 401 ) ; } $ name = $ item -> name ; $ item -> delete ( ) ; return response ( ) -> json ( [ 'message' => 'Successfully deleted item: ' . $ name ] ) ; }
Remove the specified resource from storage.
Remove the specified resource from storage .