app/Http/Controllers/UserController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $ret = ['success' => false, 'message' => 'Something went wrong!'];
        $user = User::find($id);
        if ($user) {
            if ($user->email != $request->email) {
                $request->validate(['email' => ['required', 'unique:users']]);
            }
            $data = $request->validate([
                'name'      => 'required',
            ]);
            if ($request->password != '') {
                $data += ['password' => Hash::make($request->password)];
            }
            $user->fill($data);
            if ($user->save()) {
                $ret = ['success' => true, 'message' => 'Data updated successfully!'];
            }
        }
        return response()->json($ret, 200);
    }
public function update ( Request $ request , $ id ) { $ ret = [ 'success' => false , 'message' => 'Something went wrong!' ] ; $ user = User :: find ( $ id ) ; if ( $ user ) { if ( $ user -> email != $ request -> email ) { $ request -> validate ( [ 'email' => [ 'required' , 'unique:users' ] ] ) ; } $ data = $ request -> validate ( [ 'name' => 'required' , ] ) ; if ( $ request -> password != '' ) { $ data += [ 'password' => Hash :: make ( $ request -> password ) ] ; } $ user -> fill ( $ data ) ; if ( $ user -> save ( ) ) { $ ret = [ 'success' => true , 'message' => 'Data updated successfully!' ] ; } } return response ( ) -> json ( $ ret , 200 ) ; }
Update the specified resource in storage.
Update the specified resource in storage .