refactor: update authorization logic and validation rules in ProfilRequest
This commit is contained in:
parent
328d3d21fd
commit
2e43ab100e
|
|
@ -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, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|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',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue