From 2e43ab100ef13d06abd759a204b6c28bbbb42b80 Mon Sep 17 00:00:00 2001 From: LailaWulandarii Date: Sat, 31 Jan 2026 15:12:46 +0700 Subject: [PATCH] refactor: update authorization logic and validation rules in ProfilRequest --- app/Http/Requests/Admin/ProfilRequest.php | 40 +++++++++++++++++------ 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/app/Http/Requests/Admin/ProfilRequest.php b/app/Http/Requests/Admin/ProfilRequest.php index fd9f023..51aa9de 100644 --- a/app/Http/Requests/Admin/ProfilRequest.php +++ b/app/Http/Requests/Admin/ProfilRequest.php @@ -3,26 +3,46 @@ namespace App\Http\Requests\Admin; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Support\Facades\Auth; class ProfilRequest extends FormRequest { - /** - * Determine if the user is authorized to make this request. - */ + // Mengarahkan error ke tas 'updateProfil' + protected $errorBag = 'updateProfil'; + public function authorize(): bool { - return false; + return true; } - /** - * Get the validation rules that apply to the request. - * - * @return array|string> - */ public function rules(): array { + $userId = Auth::id(); + //tambah validasi return [ - // + 'nama' => 'required|string|max:100', + 'username' => 'required|string|alpha_num|max:10|unique:users,username,' . $userId . ',id_user', + 'email' => 'required|email|unique:users,email,' . $userId . ',id_user', + 'no_wa' => 'nullable|numeric', + 'alamat' => 'nullable|string|max:200', + ]; + } + + public function messages(): array + { + return [ + 'required' => 'Kolom :attribute wajib diisi.', + 'unique' => ':attribute sudah digunakan.', + 'numeric' => ':attribute harus berupa angka.', + 'email' => 'Format :attribute tidak valid.', + ]; + } + + public function attributes(): array + { + return [ + 'nama' => 'Nama Lengkap', + 'no_wa' => 'Nomor WA', ]; } }