refactor: update authorization logic and validation rules in ProfilRequest

This commit is contained in:
LailaWulandarii 2026-01-31 15:12:46 +07:00
parent 328d3d21fd
commit 2e43ab100e
1 changed files with 30 additions and 10 deletions

View File

@ -3,26 +3,46 @@
namespace App\Http\Requests\Admin; namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
class ProfilRequest extends FormRequest class ProfilRequest extends FormRequest
{ {
/** // Mengarahkan error ke tas 'updateProfil'
* Determine if the user is authorized to make this request. protected $errorBag = 'updateProfil';
*/
public function authorize(): bool public function authorize(): bool
{ {
return false; return true;
} }
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array public function rules(): array
{ {
$userId = Auth::id();
//tambah validasi
return [ 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',
]; ];
} }
} }