validate($request, [ 'user_code' => 'required_without:agent_code', 'agent_code' => 'required_without:user_code' ]); $notifications = []; if (isset($request->user_code)) $notifications = Notification::where('user_code', $request->user_code)->get(); elseif (isset($request->agent_code)) $notifications = Notification::where('agent_code', $request->agent_code)->get(); foreach ($notifications as $notif) { $notif->data = json_decode($notif->data); } return $this->successResponse($notifications); } }