Hey,
I suggest implementing virtual DOM and WebSocket annotations to blade templates.
Additionally, I suggest simplifying the use of current WebSocket implementation.
Something like this(in pseudo-code):
/app/channels/MyChannel.php
class MyChannel extends Channel {
function canConsumer($user) {
return $user->id === 2; //whatever
}
function registerConsumer($user) {
this.registerConsumer($user->id);
}
function unregisterConsumer($user) {
this.unregisterConsumer($user->id);
}
function consume($user, $event) {
$user->updated_at = Carbon.now(); // whatever
this.propagateToBlade($event);
}
function canProducer($user) {
return $user->id === 2; //whatever
}
function registerProducer($user) {
this.registerProducer($user);
}
function produce($data) {
this.produce($data);
}
}
UserController.php
class UserController {
...
function store(Request $request) {
$user = $request->fill()->save();
$privateChannel = MyChannel::get;
if($privateChannel->canConsumer($user)) {
$privateChannel->registerConsumer($user);
}
if($privateChannel->canProducer($user)) {
$privateChannel->registerProducer($user);
}
$privateChannel->produce(['info=> 'Hey, I just registered!''])
}
...
}
myView.blade.php
<ul>
@for($item in $data) //data from controller, filled in the time of request
<li>{{$item}}</li>
@endFor)
@Channel('MyChannel', 'canConsumer')->$event //each time the event is fired on the channel, this will render new <ul> for it
<li>$event</li>
@EndChannel
</ul>
Hey, I suggest implementing virtual DOM and WebSocket annotations to blade templates. Additionally, I suggest simplifying the use of current WebSocket implementation.
Something like this(in pseudo-code):
/app/channels/MyChannel.php
UserController.php
myView.blade.php