api update
This commit is contained in:
@@ -65,4 +65,52 @@ class UserRequestController extends Controller
|
||||
|
||||
return redirect()->back()->with('info', 'Request rejected successfully.');
|
||||
}
|
||||
|
||||
public function profileUpdateRequests()
|
||||
{
|
||||
$requests = \App\Models\UpdateRequest::where('status', 'pending')
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
|
||||
return view('admin.profile_update_requests', compact('requests'));
|
||||
}
|
||||
|
||||
public function approveProfileUpdate($id)
|
||||
{
|
||||
$req = \App\Models\UpdateRequest::findOrFail($id);
|
||||
$user = \App\Models\User::findOrFail($req->user_id);
|
||||
|
||||
// FIX: Ensure data is array
|
||||
$newData = is_array($req->data) ? $req->data : json_decode($req->data, true);
|
||||
|
||||
foreach ($newData as $key => $value) {
|
||||
if ($value !== null && $value !== "") {
|
||||
if (in_array($key, ['customer_name','company_name','designation','email','mobile_no','address','pincode'])) {
|
||||
$user->$key = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$user->save();
|
||||
|
||||
$req->status = 'approved';
|
||||
$req->admin_note = 'Approved by admin on ' . now();
|
||||
$req->save();
|
||||
|
||||
return back()->with('success', 'Profile updated successfully.');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function rejectProfileUpdate($id)
|
||||
{
|
||||
$req = \App\Models\UpdateRequest::findOrFail($id);
|
||||
$req->status = 'rejected';
|
||||
$req->admin_note = 'Rejected by admin on ' . now();
|
||||
$req->save();
|
||||
|
||||
return back()->with('info', 'Profile update request rejected.');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user