03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Real Time Chat 194<br />

22 $message->data<br />

23 ]);<br />

24 break;<br />

25 }<br />

26 }<br />

27<br />

28 foreach ($this->users as $next)<br />

29 {<br />

30 // if ($next !== $user)<br />

31 // {<br />

32 $next->getSocket()->send(json_encode([<br />

33 "user" => [<br />

34 "id" => $user->getId(),<br />

35 "name" => $user->getName()<br />

36 ],<br />

37 "message" => $message<br />

38 ]));<br />

39 // }<br />

40 }<br />

41 }<br />

.<br />

This was extracted from workbench/formativ/chat/src/Formativ/Chat/Chat.php.<br />

The change we’ve made is to exclude the logic which prevented messages from being sent to the<br />

user from which they came. All messages will essentially be sent to everyone on the server now.<br />

Finishing Up The Template<br />

The final change is to the index template, as we changed the model structure and need to adjust for<br />

this in the template:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!