app/Http/Controllers/ToDoItemController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function addItem(Request $request)
    {
        $inputs = $request->validate([
            'name' => 'required|string',
            'done' => 'integer',
            'status' => 'string'
        ]);
        $item = new ToDoItem();
        $item->name = $inputs['name'];
        $item->done = isset($inputs['done']) ? $inputs['done'] : 0;
        $item->status = isset($inputs['status']) ? $inputs['status'] : 'public';
        $item->user_id = auth()->user()->id;
        $item->save();
        return response()->json([
            'message' => 'Successfully added new item: ' . $request->name
        ]);        
    }
public function addItem ( Request $ request ) { $ inputs = $ request -> validate ( [ 'name' => 'required|string' , 'done' => 'integer' , 'status' => 'string' ] ) ; $ item = new ToDoItem ( ) ; $ item -> name = $ inputs [ 'name' ] ; $ item -> done = isset ( $ inputs [ 'done' ] ) ? $ inputs [ 'done' ] : 0 ; $ item -> status = isset ( $ inputs [ 'status' ] ) ? $ inputs [ 'status' ] : 'public' ; $ item -> user_id = auth ( ) -> user ( ) -> id ; $ item -> save ( ) ; return response ( ) -> json ( [ 'message' => 'Successfully added new item: ' . $ request -> name ] ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .