Browse Source

ketiga

master
Gunawan19621 1 year ago
parent
commit
d4edf09737
  1. 56
      app/Http/Controllers/ProfileController.php
  2. 28
      app/Http/Requests/UpdatePenggunaRequest.php
  3. 32
      resources/views/profil/profil.blade.php
  4. 1
      routes/web.php

56
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.

28
app/Http/Requests/UpdatePenggunaRequest.php

@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdatePenggunaRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
*/
public function rules(): array
{
return [
//
];
}
}

32
resources/views/profil/profil.blade.php

@ -3,6 +3,8 @@
@section('content')
<div class="card">
<div class="card-body">
<form action="{{ route('update.updateprofile') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="row">
<div class="col-9">
<label for="name" class="col-form-label" style="font-size: 14px;">Nama</label>
@ -36,11 +38,6 @@
</div>
</div>
<div class="col-3 text-center">
{{-- <label for="name">Foto Profil</label><br>
<img src="{{ asset('assets/img/default-profile.png') }}" alt="{{ auth()->user()->name }}"
class="rounded-circle thumb-xl profile-image" style="width: 155px"><br>
<button type="button" class="btn btn-secondary mt-2">Upload</button>
<button type="button" class="btn btn-danger mt-2">HAPUS</button> --}}
<label for="foto">Foto Profil</label><br>
@if (auth()->user()->foto === null)
<img src="{{ asset('assets/img/default-profile.png') }}" alt="{{ auth()->user()->name }}"
@ -50,9 +47,7 @@
class="rounded-circle img-thumbnail thumb-xl profile-image"
style="width: 155px; cursor: pointer;"><br>
@endif
{{-- <button type="button" class="btn btn-secondary mt-2">Upload</button>
<button type="button" class="btn btn-danger mt-2">HAPUS</button> --}}
<div class="button-items">
{{-- <div class="button-items">
<form action="{{ route('profile-update') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group">
@ -62,18 +57,13 @@
<button type="submit" class="btn btn-sm col-4 btn-info">Simpan</button>
<a href="#" class="btn btn-sm col-4 btn-secondary">Hapus</a>
</form>
</div>
{{-- <label for="upload-image">
<img src="{{ asset('assets/img/default-profile.png') }}" alt="{{ auth()->user()->name }}"
class="rounded-circle thumb-xl profile-image" style="width: 155px; cursor: pointer;">
</label>
<input type="file" id="upload-image" style="display: none;"><br> --}}
</div> --}}
</div>
<div class="col-12">
<div class="mb-2">
<label for="tgl_lahir" class="col-form-label" style="font-size: 14px;">Tanggal
Lahir</label>
<input class="form-control" type="date"
<input class="form-control" type="date" name="tgl_lahir"
value="{{ old('tgl_lahir', auth()->user()->tgl_lahir) }}" id="tgl_lahir">
@error('tgl_lahir')
<div class="text-danger">{{ $message }}</div>
@ -101,7 +91,8 @@
<div class="mb-2">
<select class="form-control" id="agama" name="agama">
<option selected disabled>Pilih agama</option>
<option value="Islam" {{ old('agama', auth()->user()->agama) == 'Islam' ? 'selected' : '' }}>
<option value="Islam"
{{ old('agama', auth()->user()->agama) == 'Islam' ? 'selected' : '' }}>
Islam</option>
<option value="Kristen"
{{ old('agama', auth()->user()->agama) == 'Kristen' ? 'selected' : '' }}>Kristen
@ -109,9 +100,11 @@
<option value="Katolik"
{{ old('agama', auth()->user()->agama) == 'Katolik' ? 'selected' : '' }}>Katolik
</option>
<option value="Hindu" {{ old('agama', auth()->user()->agama) == 'Hindu' ? 'selected' : '' }}>
<option value="Hindu"
{{ old('agama', auth()->user()->agama) == 'Hindu' ? 'selected' : '' }}>
Hindu</option>
<option value="Buddha" {{ old('agama', auth()->user()->agama) == 'Buddha' ? 'selected' : '' }}>
<option value="Buddha"
{{ old('agama', auth()->user()->agama) == 'Buddha' ? 'selected' : '' }}>
Buddha
</option>
<option value="Konghucu"
@ -135,9 +128,10 @@
</div>
<div class="col-12 d-flex justify-content-end">
<button type="button" class="btn btn-danger mt-2 col-1">BATAL</button>
<button type="button" class="btn btn-success mt-2 ml-2 col-1">SIMPAN</button>
<button type="submit" class="btn btn-success mt-2 ml-2 col-1">SIMPAN</button>
</div>
</div>
</form>
</div>
</div>

1
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');
});

Loading…
Cancel
Save