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)
    {
        $cek = User::where('username', $request->username)->get()->count();
        if($cek > 0){
            return response()->json([
                'status'=> false,
                'error' => 'Username Telah Terdaftar'
            ]);
        }
        else {
            $update = User::find($id)->update([
                'nama' => $request->nama,
                'username' => $request->username,
                'password' => bcrypt($request->password),
                'outlet_id' => $request->outlet_id,
                'role' => $request->role
            ]);
            if($update){
                return response()->json([
                    'status' => true
                ]);
            }
            else{
                return response()->json([
                    'status' => false
                ]);
            }
        }
    }
public function update ( Request $ request , $ id ) { $ cek = User :: where ( 'username' , $ request -> username ) -> get ( ) -> count ( ) ; if ( $ cek > 0 ) { return response ( ) -> json ( [ 'status' => false , 'error' => 'Username Telah Terdaftar' ] ) ; } else { $ update = User :: find ( $ id ) -> update ( [ 'nama' => $ request -> nama , 'username' => $ request -> username , 'password' => bcrypt ( $ request -> password ) , 'outlet_id' => $ request -> outlet_id , 'role' => $ request -> role ] ) ; if ( $ update ) { return response ( ) -> json ( [ 'status' => true ] ) ; } else { return response ( ) -> json ( [ 'status' => false ] ) ; } } }
Update the specified resource in storage.
Update the specified resource in storage .