app/Http/Controllers/PpcController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Ppc  $ppc
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Ppc $ppc)
    {
        if (request()->input('password') == null) {
            $dataUser = request()->validate([
                'username' => 'required|string|max:100',
                'email' => 'required|email|unique:users,email,'.$ppc->user->id
            ]);
        }else{
            $dataUser = request()->validate([
                'username' => 'required|string|max:100',
                'email' => 'required|email|unique:users,email,'.$ppc->user->id,
                'password' => 'required|min:6',
                'confirm-password' => 'required|same:password|min:6'
            ]);
            $dataUser['password'] = \bcrypt($dataUser['password']);
        }
        $dataPPC = request()->validate([
            'nama' => 'required|string|max:120',
            'gender' => 'required|string|in:L,P',
            'tanggal_lahir' => 'required|date',
            'alamat' => 'required|string|max:190',
            'no_hp' => 'required|string|max:20'
        ]);
        $ppc->update($dataPPC);
        $ppc->user->update($dataUser);
        return redirect()->route('ppc.index')->with('success', 'Data Staff PPC '.$ppc->nama.' berhasil diubah');
    }
public function update ( Request $ request , Ppc $ ppc ) { if ( request ( ) -> input ( 'password' ) == null ) { $ dataUser = request ( ) -> validate ( [ 'username' => 'required|string|max:100' , 'email' => 'required|email|unique:users,email,' . $ ppc -> user -> id ] ) ; } else { $ dataUser = request ( ) -> validate ( [ 'username' => 'required|string|max:100' , 'email' => 'required|email|unique:users,email,' . $ ppc -> user -> id , 'password' => 'required|min:6' , 'confirm-password' => 'required|same:password|min:6' ] ) ; $ dataUser [ 'password' ] = \ bcrypt ( $ dataUser [ 'password' ] ) ; } $ dataPPC = request ( ) -> validate ( [ 'nama' => 'required|string|max:120' , 'gender' => 'required|string|in:L,P' , 'tanggal_lahir' => 'required|date' , 'alamat' => 'required|string|max:190' , 'no_hp' => 'required|string|max:20' ] ) ; $ ppc -> update ( $ dataPPC ) ; $ ppc -> user -> update ( $ dataUser ) ; return redirect ( ) -> route ( 'ppc.index' ) -> with ( 'success' , 'Data Staff PPC ' . $ ppc -> nama . ' berhasil diubah' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .