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)
    {
        $validasi = $request->validate([
            'nama' => 'required',
            'alamat' => 'required',
            'email' => 'required',
            'password' => 'required|max:10|min:5',
            'level' => 'required',
            'telepon' => 'required',
        ], [
            'nama.required' => 'Masukan Nama',
            'alamat.required' => 'Alamat Tidak Boleh Kosong',
            'email.required' => 'Masukan email',
            'password.required' => 'Masukan Password',
            'password.min' => 'Masukan Password Minimal 5 digit',
            'password.max' => 'Masukan Password Maximal 10 digit',
            'level.required' => 'Pilih Jabatan terlebih dahulu ',
            'telepon.required' => 'Masukan Nomor Telepon',
        ]);
        $user = User::findOrFail($id);
        $foto = $request->file('image');
        if ($foto) {
            $request['foto'] = $this->uploadFoto($foto, $request->nama, 'profile', true, $user->foto);
        }
        if ($request->password) {
            $request['password'] = Hash::make($request->password);
        } else {
            $request['password'] = $user->password;
        }
        $user->update($request->all());
        return redirect()->route('user.index')->with('message','data berhasil di ubah');
    }
public function update ( Request $ request , $ id ) { $ validasi = $ request -> validate ( [ 'nama' => 'required' , 'alamat' => 'required' , 'email' => 'required' , 'password' => 'required|max:10|min:5' , 'level' => 'required' , 'telepon' => 'required' , ] , [ 'nama.required' => 'Masukan Nama' , 'alamat.required' => 'Alamat Tidak Boleh Kosong' , 'email.required' => 'Masukan email' , 'password.required' => 'Masukan Password' , 'password.min' => 'Masukan Password Minimal 5 digit' , 'password.max' => 'Masukan Password Maximal 10 digit' , 'level.required' => 'Pilih Jabatan terlebih dahulu ' , 'telepon.required' => 'Masukan Nomor Telepon' , ] ) ; $ user = User :: findOrFail ( $ id ) ; $ foto = $ request -> file ( 'image' ) ; if ( $ foto ) { $ request [ 'foto' ] = $ this -> uploadFoto ( $ foto , $ request -> nama , 'profile' , true , $ user -> foto ) ; } if ( $ request -> password ) { $ request [ 'password' ] = Hash :: make ( $ request -> password ) ; } else { $ request [ 'password' ] = $ user -> password ; } $ user -> update ( $ request -> all ( ) ) ; return redirect ( ) -> route ( 'user.index' ) -> with ( 'message' , 'data berhasil di ubah' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// 'foto' => 'required' // 'foto.required' => 'Masukan Foto',