What seems to be the problem:
I used this great article (https://reinink.ca/articles/dynamic-relationships-in-laravel-using-subqueries) to help me include the single latest relation.
It uses a scope query on my model. That works absolutely fine, but when I submit my form the public property seems to lose the scoped relation but everything else persists.
Steps to Reproduce:
Are you using the latest version of Livewire:
^1.0
Do you have any screenshots or code examples:
public function updatedToTank()
{
$this->transit =
Tank::withLastEvent()
->with('site')
->identifier($this->toTank)
->site($this->site()->id)
->first();
}
when the toTank field changes I fetch the relevant model, this works well because it only runs after my validateOnly call is successful in the main updated method.
But when I submit the form which is a new Livewire request, then try to access transit->lastEvent it is null in my submit handler method, so the scoped relation isn’t persisted.
I should note that the normal with(‘site’) works fine, I can access transit->site inside the submit handler.
Can anyone help or has anyone seen this before? Many thanks.