murdercode/yaTTA

View on GitHub
app/Livewire/Chat/ChatInput.php

Summary

Maintainability
A
0 mins
Test Coverage
F
33%
<?php

namespace App\Livewire\Chat;

use App\Livewire\Forms\ChatForm;
use App\Models\Chat;
use Livewire\Component;

class ChatInput extends Component
{
    public ChatForm $form;

    public Chat $chat;

    public string $autocomplete = '';

    //    public function updatingFormInput()
    //    {
    //        $this->autocomplete = strlen($this->form->input) >= 3 ? $this->form->input.rand(1, 1000) : '';
    //    }

    /**
     * Run when user submit the input field.
     */
    public function save()
    {

        // Save the chat in database
        $this->chat->addInput($this->form->input);

        // Reset the form
        $this->form->reset();

        $this->dispatch('input-saved')->to('chat.chat-messages');

    }

    public function render()
    {
        return view('livewire.chat.chat-input');
    }
}