App\Http\Controllers\AccountApiController::updatePushNotifications PHP Method

updatePushNotifications() public method

public updatePushNotifications ( Illuminate\Http\Request $request )
$request Illuminate\Http\Request
    public function updatePushNotifications(Request $request)
    {
        $account = Auth::user()->account;
        $devices = json_decode($account->devices, TRUE);
        if (count($devices) < 1) {
            return $this->errorResponse(['message' => 'No registered devices.'], 400);
        }
        for ($x = 0; $x < count($devices); $x++) {
            if ($devices[$x]['email'] == Auth::user()->username) {
                $newDevice = ['token' => $devices[$x]['token'], 'email' => $devices[$x]['email'], 'device' => $devices[$x]['device'], 'account_key' => $account->account_key, 'notify_sent' => $request->notify_sent, 'notify_viewed' => $request->notify_viewed, 'notify_approved' => $request->notify_approved, 'notify_paid' => $request->notify_paid];
                $devices[$x] = $newDevice;
                $account->devices = json_encode($devices);
                $account->save();
                return $this->response($newDevice);
            }
        }
    }