49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ProfilRequest extends FormRequest
|
|
{
|
|
// Mengarahkan error ke tas 'updateProfil'
|
|
protected $errorBag = 'updateProfil';
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
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',
|
|
];
|
|
}
|
|
}
|