class Chat extends Component
{
protected $listeners = ['messageAdded'];
public $total;
public function mount()
{
$this->total = ChatMessages::count();
}
public function messageAdded()
{
$this->total = ChatMessages::count();
}
public function render()
{
return view('livewire.chat');
}
public function sendChatMessage(Request $request) {
if (Auth::check()) {
$chat = ChatModel::firstOrCreate(['user_id' => Auth::user()->id]);
} else {
$chat = ChatModel::firstOrCreate(['ip' => $request->ip()]);
}
$message = $chat->messages()->create([
'message' => $request->input('message'),
'status' => 'unread',
]);
$this->emit('messageAdded');
return true;
}
}
Возможно ли обновить с такого запроса? Или только с фронта обновляется?