From d4edf0973766cdb7d6c13d6222070117333e1587 Mon Sep 17 00:00:00 2001 From: Gunawan19621 Date: Tue, 29 Aug 2023 20:43:40 +0700 Subject: [PATCH] ketiga --- app/Http/Controllers/ProfileController.php | 56 ++++- app/Http/Requests/UpdatePenggunaRequest.php | 28 +++ resources/views/profil/profil.blade.php | 246 ++++++++++---------- routes/web.php | 1 + 4 files changed, 196 insertions(+), 135 deletions(-) create mode 100644 app/Http/Requests/UpdatePenggunaRequest.php diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 736ee88..dbfaea8 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Redirect; use App\Http\Requests\ProfileUpdateRequest; +use App\Http\Requests\UpdatePenggunaRequest; use Illuminate\Support\Facades\Storage; class ProfileController extends Controller @@ -27,6 +28,43 @@ class ProfileController extends Controller return view('profil.profil'); } + //Proses update Profile + public function update(UpdatePenggunaRequest $request, $id) + { + try { + $pengguna = User::findOrFail($id); + $pengguna->update($request->validated()); + return redirect()->route('profile.edit')->with('success', 'Profil pengguna berhasil perbaharui'); + } catch (\Throwable $th) { + dd($th); + return redirect()->route('pengguna.index')->with('error', 'Data pengguna gagal diubah'); + } + } + // public function updateprofile(Request $request) + // { + // // dd('oke'); + // $messages = [ + // 'tgl_lahir.date_format' => 'Format tanggal lahir harus sesuai dengan d/m/Y.', + // ]; + + // try { + // $request->validate([ + // 'name' => 'required', + // 'email' => 'required', + // 'phone' => 'required', + // 'tgl_lahir' => 'date', + // 'jenis_kelamin' => 'required', + // 'agama' => 'required', + // 'alamat' => 'required', + // ], $messages); + // // dd($request->all()); + // return back()->with('success', 'Profil berhasil di update.'); + // } catch (\Throwable $th) { + // // dd($th); + // return back()->with('eror', 'Profil gagal di update.'); + // } + // } + //Proses update Profile Photo public function updatePhoto(Request $request) { @@ -44,18 +82,18 @@ class ProfileController extends Controller } //Proses update Profile Informasi - public function update(ProfileUpdateRequest $request): RedirectResponse - { - $request->user()->fill($request->validated()); + // public function update(ProfileUpdateRequest $request): RedirectResponse + // { + // $request->user()->fill($request->validated()); - if ($request->user()->isDirty('email')) { - $request->user()->email_verified_at = null; - } + // if ($request->user()->isDirty('email')) { + // $request->user()->email_verified_at = null; + // } - $request->user()->save(); + // $request->user()->save(); - return Redirect::back()->with('status', 'profile-updated'); - } + // return Redirect::back()->with('status', 'profile-updated'); + // } /** * Delete the user's account. diff --git a/app/Http/Requests/UpdatePenggunaRequest.php b/app/Http/Requests/UpdatePenggunaRequest.php new file mode 100644 index 0000000..452d807 --- /dev/null +++ b/app/Http/Requests/UpdatePenggunaRequest.php @@ -0,0 +1,28 @@ + + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/resources/views/profil/profil.blade.php b/resources/views/profil/profil.blade.php index 7d30f1f..db8a572 100644 --- a/resources/views/profil/profil.blade.php +++ b/resources/views/profil/profil.blade.php @@ -3,141 +3,135 @@ @section('content')
-
-
- -
- - @error('name') -
{{ $message }}
- @enderror -
+
+ @csrf +
+
+ +
+ + @error('name') +
{{ $message }}
+ @enderror +
- -
- - @error('email') -
{{ $message }}
- @enderror -
+ +
+ + @error('email') +
{{ $message }}
+ @enderror +
- -
- - @error('phone') -
{{ $message }}
- @enderror -
-
-
- {{--
- {{ auth()->user()->name }}
- - --}} -
- @if (auth()->user()->foto === null) - {{ auth()->user()->name }}
- @else - {{ auth()->user()->name }}
- @endif - {{-- - --}} -
- - @csrf -
- -
- - Hapus - + +
+ + @error('phone') +
{{ $message }}
+ @enderror +
- {{-- -
--}} -
-
-
- - - @error('tgl_lahir') -
{{ $message }}
- @enderror +
+
+ @if (auth()->user()->foto === null) + {{ auth()->user()->name }}
+ @else + {{ auth()->user()->name }}
+ @endif + {{--
+
+ @csrf +
+ +
+ + Hapus +
+
--}}
+
+
+ + + @error('tgl_lahir') +
{{ $message }}
+ @enderror +
- -
- - @error('jenis_kelamin') -
{{ $message }}
- @enderror -
+ +
+ + @error('jenis_kelamin') +
{{ $message }}
+ @enderror +
- -
- - @error('agama') -
{{ $message }}
- @enderror -
+ +
+ + @error('agama') +
{{ $message }}
+ @enderror +
- -
- - @error('alamat') -
{{ $message }}
- @enderror -
+ +
+ + @error('alamat') +
{{ $message }}
+ @enderror +
+
+
+ + +
-
- - -
-
+
diff --git a/routes/web.php b/routes/web.php index 84db265..ad2ee61 100644 --- a/routes/web.php +++ b/routes/web.php @@ -34,6 +34,7 @@ Route::middleware('auth')->group(function () { Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit'); Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update'); Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy'); + Route::post('/profile/update', [ProfileController::class, 'updateprofile'])->name('update.updateprofile'); Route::post('/profile-update', [ProfileController::class, 'updatePhoto'])->name('profile-update'); Route::get('/setting', [ProfileController::class, 'setting'])->name('profile.setting'); });