Validation errors

Hi,
I am not able to access session errors after validation. Trying to output usual
debug(session('errors'));
gives null.

I guess in view it might becomes magically accessible, but how to access error bag from code?
Thanks!

$this->getErrorBag()

Funny, it works, but ErrorBag is just kept after validation forever. I guess it require manual emptying.

Weird, I wonder why it’s not clearing out. You can use $this->resetErrorBag() The validation logic is here to see what other methods are available https://github.com/livewire/livewire/blob/master/src/ComponentConcerns/ValidatesInput.php.

Even more interesting…

This is where I pulling the error bag:

public function render()
{
        Flatform::context()->setErrors($this->getErrorBag()); // <<<<<
        if(!$this->item && $this->item_id) $this->loadItem();
        return view('livewire.extraction.details')
            ->with('item', $this->item)
            ->with('host', $this);

}

Here I resetting error bag and initializing “editing”

    public function startEdit()
    {
        $this->editing = true;
        $this->loadItem();
        $this->title        = $this->item->title;
        $this->type_id      = $this->item->type_id;
        $this->key          = $this->item->key;
        $this->description  = $this->item->description;
        $this->required     = $this->item->required;
        $this->resetErrorBag();

    }

And validation on “submit” button:

public function updateItem()
    {
        $validated = $this->validate([
            'title' => 'required|min:6',
            'type_id' => 'required|integer',
            'description' => 'sometimes|string',
            'key' => 'sometimes|string',
            'required' => 'sometimes|boolean',
        ]);
        $this->loadItem();
        $this->item->fill($validated);
        $this->item->update();
        $this->emit((Item::EVENT_PREFIX . $this->item_id[0]), true);
    }

It works, but when “updateItem” triggered first time (I put 1 character in “title”) - error bag is empty, but validation was not passed. Only when I click “submit” second time and “updateItem” is triggered one more time then my view renders with errors…

What i am missing??

Nevermind, it seems to be a my issue…
I cannot correctly word it now, but it seems that rendering of view happens somewhere disconnected from “render()” function of a component.