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. 246
      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\Http\RedirectResponse;
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use App\Http\Requests\ProfileUpdateRequest; use App\Http\Requests\ProfileUpdateRequest;
use App\Http\Requests\UpdatePenggunaRequest;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
class ProfileController extends Controller class ProfileController extends Controller
@ -27,6 +28,43 @@ class ProfileController extends Controller
return view('profil.profil'); 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 //Proses update Profile Photo
public function updatePhoto(Request $request) public function updatePhoto(Request $request)
{ {
@ -44,18 +82,18 @@ class ProfileController extends Controller
} }
//Proses update Profile Informasi //Proses update Profile Informasi
public function update(ProfileUpdateRequest $request): RedirectResponse // public function update(ProfileUpdateRequest $request): RedirectResponse
{ // {
$request->user()->fill($request->validated()); // $request->user()->fill($request->validated());
if ($request->user()->isDirty('email')) { // if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null; // $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. * 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 [
//
];
}
}

246
resources/views/profil/profil.blade.php

@ -3,141 +3,135 @@
@section('content') @section('content')
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<div class="row"> <form action="{{ route('update.updateprofile') }}" method="POST" enctype="multipart/form-data">
<div class="col-9"> @csrf
<label for="name" class="col-form-label" style="font-size: 14px;">Nama</label> <div class="row">
<div class="mb-2"> <div class="col-9">
<input pattern="[^0-9]+" required oninput="this.value=this.value.replace(/[0-9]/g,'');" <label for="name" class="col-form-label" style="font-size: 14px;">Nama</label>
class="form-control" type="text" id="name" name="name" <div class="mb-2">
value="{{ old('name', auth()->user()->name) }}" placeholder="Masukan nama anda"> <input pattern="[^0-9]+" required oninput="this.value=this.value.replace(/[0-9]/g,'');"
@error('name') class="form-control" type="text" id="name" name="name"
<div class="text-danger">{{ $message }}</div> value="{{ old('name', auth()->user()->name) }}" placeholder="Masukan nama anda">
@enderror @error('name')
</div> <div class="text-danger">{{ $message }}</div>
@enderror
</div>
<label for="email" class="col-form-label" style="font-size: 14px;">Alamat <label for="email" class="col-form-label" style="font-size: 14px;">Alamat
Email</label> Email</label>
<div class="mb-2"> <div class="mb-2">
<input class="form-control" type="email" id="email" name="email" <input class="form-control" type="email" id="email" name="email"
value="{{ old('email', auth()->user()->email) }}" readonly> value="{{ old('email', auth()->user()->email) }}" readonly>
@error('email') @error('email')
<div class="text-danger">{{ $message }}</div> <div class="text-danger">{{ $message }}</div>
@enderror @enderror
</div> </div>
<label for="phone" class="col-form-label" style="font-size: 14px;">No. <label for="phone" class="col-form-label" style="font-size: 14px;">No.
Handphone</label> Handphone</label>
<div class="mb-2"> <div class="mb-2">
<input class="form-control" type="tel" id="phone" name="phone" <input class="form-control" type="tel" id="phone" name="phone"
value="{{ old('phone', auth()->user()->phone) }}" placeholder="Masukan nomor telepone anda"> value="{{ old('phone', auth()->user()->phone) }}" placeholder="Masukan nomor telepone anda">
@error('phone') @error('phone')
<div class="text-danger">{{ $message }}</div> <div class="text-danger">{{ $message }}</div>
@enderror @enderror
</div> </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 }}"
class="rounded-circle thumb-xl profile-image" style="width: 155px; cursor: pointer;"><br>
@else
<img src="{{ asset('storage/' . auth()->user()->foto) }}" alt="{{ auth()->user()->name }}"
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">
<form action="{{ route('profile-update') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group">
<input type="file" name="foto" id="photo" class="form-control-file d-none"
accept=".jpeg,.jpg,.png,.jfif">
</div>
<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> </div>
{{-- <label for="upload-image"> <div class="col-3 text-center">
<img src="{{ asset('assets/img/default-profile.png') }}" alt="{{ auth()->user()->name }}" <label for="foto">Foto Profil</label><br>
class="rounded-circle thumb-xl profile-image" style="width: 155px; cursor: pointer;"> @if (auth()->user()->foto === null)
</label> <img src="{{ asset('assets/img/default-profile.png') }}" alt="{{ auth()->user()->name }}"
<input type="file" id="upload-image" style="display: none;"><br> --}} class="rounded-circle thumb-xl profile-image" style="width: 155px; cursor: pointer;"><br>
</div> @else
<div class="col-12"> <img src="{{ asset('storage/' . auth()->user()->foto) }}" alt="{{ auth()->user()->name }}"
<div class="mb-2"> class="rounded-circle img-thumbnail thumb-xl profile-image"
<label for="tgl_lahir" class="col-form-label" style="font-size: 14px;">Tanggal style="width: 155px; cursor: pointer;"><br>
Lahir</label> @endif
<input class="form-control" type="date" {{-- <div class="button-items">
value="{{ old('tgl_lahir', auth()->user()->tgl_lahir) }}" id="tgl_lahir"> <form action="{{ route('profile-update') }}" method="POST" enctype="multipart/form-data">
@error('tgl_lahir') @csrf
<div class="text-danger">{{ $message }}</div> <div class="form-group">
@enderror <input type="file" name="foto" id="photo" class="form-control-file d-none"
accept=".jpeg,.jpg,.png,.jfif">
</div>
<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> --}}
</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" name="tgl_lahir"
value="{{ old('tgl_lahir', auth()->user()->tgl_lahir) }}" id="tgl_lahir">
@error('tgl_lahir')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<label for="jenis_kelamin" class="col-form-label" style="font-size: 14px;">Jenis <label for="jenis_kelamin" class="col-form-label" style="font-size: 14px;">Jenis
Kelamin</label> Kelamin</label>
<div class="mb-2"> <div class="mb-2">
<select class="form-control" id="jenis_kelamin" name="jenis_kelamin"> <select class="form-control" id="jenis_kelamin" name="jenis_kelamin">
<option selected disabled>Pilih jenis kelamin</option> <option selected disabled>Pilih jenis kelamin</option>
<option value="L" <option value="L"
{{ old('jenis_kelamin', auth()->user()->jenis_kelamin) == 'L' ? 'selected' : '' }}> {{ old('jenis_kelamin', auth()->user()->jenis_kelamin) == 'L' ? 'selected' : '' }}>
Laki-laki</option> Laki-laki</option>
<option value="P" <option value="P"
{{ old('jenis_kelamin', auth()->user()->jenis_kelamin) == 'P' ? 'selected' : '' }}> {{ old('jenis_kelamin', auth()->user()->jenis_kelamin) == 'P' ? 'selected' : '' }}>
Perempuan</option> Perempuan</option>
</select> </select>
@error('jenis_kelamin') @error('jenis_kelamin')
<div class="text-danger">{{ $message }}</div> <div class="text-danger">{{ $message }}</div>
@enderror @enderror
</div> </div>
<label for="agama" class="col-form-label" style="font-size: 14px;">Agama</label> <label for="agama" class="col-form-label" style="font-size: 14px;">Agama</label>
<div class="mb-2"> <div class="mb-2">
<select class="form-control" id="agama" name="agama"> <select class="form-control" id="agama" name="agama">
<option selected disabled>Pilih agama</option> <option selected disabled>Pilih agama</option>
<option value="Islam" {{ old('agama', auth()->user()->agama) == 'Islam' ? 'selected' : '' }}> <option value="Islam"
Islam</option> {{ old('agama', auth()->user()->agama) == 'Islam' ? 'selected' : '' }}>
<option value="Kristen" Islam</option>
{{ old('agama', auth()->user()->agama) == 'Kristen' ? 'selected' : '' }}>Kristen <option value="Kristen"
</option> {{ old('agama', auth()->user()->agama) == 'Kristen' ? 'selected' : '' }}>Kristen
<option value="Katolik" </option>
{{ old('agama', auth()->user()->agama) == 'Katolik' ? 'selected' : '' }}>Katolik <option value="Katolik"
</option> {{ old('agama', auth()->user()->agama) == 'Katolik' ? 'selected' : '' }}>Katolik
<option value="Hindu" {{ old('agama', auth()->user()->agama) == 'Hindu' ? 'selected' : '' }}> </option>
Hindu</option> <option value="Hindu"
<option value="Buddha" {{ old('agama', auth()->user()->agama) == 'Buddha' ? 'selected' : '' }}> {{ old('agama', auth()->user()->agama) == 'Hindu' ? 'selected' : '' }}>
Buddha Hindu</option>
</option> <option value="Buddha"
<option value="Konghucu" {{ old('agama', auth()->user()->agama) == 'Buddha' ? 'selected' : '' }}>
{{ old('agama', auth()->user()->agama) == 'Konghucu' ? 'selected' : '' }}>Konghucu Buddha
</option> </option>
</select> <option value="Konghucu"
@error('agama') {{ old('agama', auth()->user()->agama) == 'Konghucu' ? 'selected' : '' }}>Konghucu
<div class="text-danger">{{ $message }}</div> </option>
@enderror </select>
</div> @error('agama')
<div class="text-danger">{{ $message }}</div>
@enderror
</div>
<label for="alamat" class="col-form-label" style="font-size: 14px;">Alamat</label> <label for="alamat" class="col-form-label" style="font-size: 14px;">Alamat</label>
<div class="mb-2"> <div class="mb-2">
<textarea pattern="[^0-9]+" required oninput="this.value=this.value.replace(/[0-9]/g,'');" class="form-control" <textarea pattern="[^0-9]+" required oninput="this.value=this.value.replace(/[0-9]/g,'');" class="form-control"
id="alamat" name="alamat" placeholder="Masukkan alamat Anda">{{ old('alamat', auth()->user()->alamat) }}</textarea> id="alamat" name="alamat" placeholder="Masukkan alamat Anda">{{ old('alamat', auth()->user()->alamat) }}</textarea>
@error('alamat') @error('alamat')
<div class="text-danger">{{ $message }}</div> <div class="text-danger">{{ $message }}</div>
@enderror @enderror
</div> </div>
</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="submit" class="btn btn-success mt-2 ml-2 col-1">SIMPAN</button>
</div>
</div> </div>
<div class="col-12 d-flex justify-content-end"> </form>
<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>
</div>
</div>
</div> </div>
</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::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update'); Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy'); 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::post('/profile-update', [ProfileController::class, 'updatePhoto'])->name('profile-update');
Route::get('/setting', [ProfileController::class, 'setting'])->name('profile.setting'); Route::get('/setting', [ProfileController::class, 'setting'])->name('profile.setting');
}); });

Loading…
Cancel
Save