A
A
Alexander2016-11-09 14:09:56
Laravel
Alexander, 2016-11-09 14:09:56

Unable to save data to the database (Ratchet)?

Wrote a simple chat with Ratchet

public function onMessage(ConnectionInterface $from, $msg)
    {
              DB::table('chat')->insert([
                        'visa_order_id' => 1,
                        'user_id' => 1,
                        'text' => 1,
        ]);
    }

I'm trying to test save the data, but I get an error:
An error has occurred: A facade root has not been set.
Connection 53 has disconnected

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lynnikvadim, 2016-11-09
@lynnikvadim

public function onMessage(ConnectionInterface $from, $msg) {
$numRecv = count($this->clients) - 1;
echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
, $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's ');
foreach ($this->clients as $client) {
$client->send($this->response->make($msg));
$ms=json_decode($msg);
$ms= (object)$ms;
\App\Messages::create(['body'=>$session_name,'user_id'=>$ms->client->data->user_id,'chat_id'=>1]);
}
}
works like this for me

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question