fix code
This commit is contained in:
@@ -23,7 +23,6 @@ class ProfileController extends Controller
|
||||
public function edit(EditRequest $request): JsonResponse
|
||||
{
|
||||
$expert = $request->user('expert');
|
||||
// $expert->update($request->validated());
|
||||
|
||||
$expert->update([
|
||||
'username' => $request->username,
|
||||
|
||||
@@ -26,53 +26,14 @@ class EditRequest extends FormRequest
|
||||
{
|
||||
$user = $this->user();
|
||||
return [
|
||||
'first_name' => [
|
||||
Rule::prohibitedIf($user->kyc_status == 1), 'string',
|
||||
],
|
||||
|
||||
'last_name' => [
|
||||
Rule::prohibitedIf($user->kyc_status == 1), 'string',
|
||||
],
|
||||
|
||||
'national_id' => [
|
||||
Rule::prohibitedIf($user->kyc_status == 1), 'string',
|
||||
],
|
||||
'username' => 'string|max:255',
|
||||
|
||||
'first_name' => 'required|string',
|
||||
'last_name' => 'required|string',
|
||||
'national_id' => 'required',
|
||||
'email' => 'string|email|max:255',
|
||||
'phone_number' => 'string',
|
||||
'province_id' => 'string',
|
||||
'city_id' => 'string',
|
||||
];
|
||||
}
|
||||
|
||||
public function after(): array
|
||||
{
|
||||
return [
|
||||
function (Validator $validator) {
|
||||
$user = $this->user();
|
||||
|
||||
if (! $user) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($user->kyc_status == 1) {
|
||||
$lockedFields = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
'national_id',
|
||||
];
|
||||
|
||||
foreach ($lockedFields as $field) {
|
||||
if ($this->filled($field)) {
|
||||
$validator->errors()->add(
|
||||
$field,
|
||||
'After KYC approval, you cannot change this field.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,7 @@ class ProfileController extends Controller
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$data = $request->validated();
|
||||
|
||||
if ($user->kyc_status === 2) {
|
||||
$data->safe()->except(['first_name', 'last_name' ,'national_id']);
|
||||
}
|
||||
|
||||
$user->update($data);
|
||||
$user->update($request->validated());
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
@@ -25,31 +25,17 @@ class EditRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
$user = $this->user();
|
||||
$isKycApproved = (int) $user->kyc_status === 2;
|
||||
|
||||
return [
|
||||
'first_name' => [
|
||||
Rule::prohibitedIf($isKycApproved),
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::prohibitedIf($user->kyc_status == 1), 'string',
|
||||
],
|
||||
|
||||
'last_name' => [
|
||||
Rule::prohibitedIf($isKycApproved),
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::prohibitedIf($user->kyc_status == 1), 'string',
|
||||
],
|
||||
|
||||
'national_id' => [
|
||||
Rule::prohibitedIf($isKycApproved),
|
||||
'required',
|
||||
'string',
|
||||
'max:20',
|
||||
Rule::unique('users', 'national_id')->ignore($user->id),
|
||||
Rule::prohibitedIf($user->kyc_status == 1), 'string',
|
||||
],
|
||||
|
||||
'address' => 'required',
|
||||
'postal_code' => 'required',
|
||||
'phone_number' => 'required',
|
||||
@@ -62,9 +48,21 @@ class EditRequest extends FormRequest
|
||||
return [
|
||||
function (Validator $validator) {
|
||||
$user = $this->user();
|
||||
if ($user->kyc_status == 1) {
|
||||
$lockedFields = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
'national_id',
|
||||
];
|
||||
|
||||
if ( $user->kyc_status === 1) {
|
||||
if
|
||||
foreach ($lockedFields as $field) {
|
||||
if ($this->filled($field)) {
|
||||
$validator->errors()->add(
|
||||
$field,
|
||||
'you cannot change this field.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user