Как перенести данные с сервера nodejs на PHP? - PullRequest
0 голосов
/ 27 апреля 2020

В моем nodejs я использую сокеты, которые выводят данные пользователю:

io.emit ('notify', {
msg_link: `/Notify_link`,
msg_dep: `${me.personaName} ${data.code}`,
status: 'success'
});

Все работает хорошо. В javascript я обрабатываю данные:

socket.on('notify', (data) => {
    if (data.id === USER_ID) {
        const link = data.msg_link;
        const message = data.msg_dep;
        updateNotify_info(message, link);
        Inv.update();
    }
});

И const link делает POST для моего laravel приложения, и там я уже ввожу данные в базу данных:

public function getNotify_link() {
    Notify::create(
        [
        'user_id' => $this->user->id,
        'title' => 'Success',
        'message' => 'Name: {name} Code: {code}',
        'status' => '1',
        ]);
    return response()->json(['success' => true, 'status' => 'success']);
}

Вопрос в том, как передать переменные, которые я получаю в nodejs: ${me.personaName} и ${data.code}, в функцию getNotify_link() сайта, чтобы добавить эти данные в базу данных?

РЕДАКТИРОВАТЬ: updateNotify_info() функция в JS:

function updateNotify_info(message, svg, link) {
    $.post(`${link}`, function (data) {
        var notification = $('<div>', {"class": "notification"});
        var block = $('<div>', {"class": "notification__content"});

        block.append($('<div>', {"text": 'Title', "class": "notification__title"}));
        block.append($('<div>', {"text": `${message}`, "class": "notification__text"}));

        block.append($('<div>', {"text": new Date().toISOString().slice(0, 10), "class": "notification__date"}));

        notification.append(`${svg}`);           
        notification.append(block);

        notification.prependTo("#notifications .scroll");


        $('.sidebar-nav__item_notify').addClass(' sidebar-nav__notifications sidebar-nav__notifications_unread sidebar-nav__notifications_animated')
        setTimeout(function(){
            $('.sidebar-nav__item_notify').removeClass(' sidebar-nav__notifications sidebar-nav__notifications_animated')
        },2000);
    });
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...