--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class PleaseRefresh extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'app:refresh';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Ask clients to reload';
+
+ /**
+ * Execute the console command.
+ *
+ * @return int
+ */
+ public function handle()
+ {
+ \App\Events\PleaseRefresh::dispatch();
+ return 0;
+ }
+}
--- /dev/null
+<?php
+
+namespace App\Events;
+
+use Illuminate\Broadcasting\Channel;
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Broadcasting\PresenceChannel;
+use Illuminate\Broadcasting\PrivateChannel;
+use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Queue\SerializesModels;
+
+class PleaseRefresh implements ShouldBroadcast
+{
+ use Dispatchable, InteractsWithSockets, SerializesModels;
+
+ /**
+ * Create a new event instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ //
+ }
+
+ /**
+ * Get the channels the event should broadcast on.
+ *
+ * @return \Illuminate\Broadcasting\Channel|array
+ */
+ public function broadcastOn()
+ {
+ return new Channel('App.Control');
+ }
+
+}
};
}, []);
+ useEffect(() => {
+ window.Echo.channel('App.Control')
+ .listen('PleaseRefresh', () => {
+ location.reload();
+ });
+ return () => {
+ window.Echo.leave('App.Control');
+ };
+ }, []);
+
return <BrowserRouter>
<UserContext.Provider value={user}>
<Header doLogout={doLogout} />
},
rounds: {
date: '{{ date, L }}',
+ empty: 'Noch keine Runde gestartet',
heading: 'Runden',
new: 'Neue Runde',
},
*/
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
- return (int) $user->id === (int) $id;
+ return (int) $user->id === (int) $id;
+});
+
+Broadcast::channel('App.Control', function ($user) {
+ return true;
});