I am submitting a form and in my controller i use handleRequest to validate the form.
Lets say i try to update my object name 'object' It has an id, name and color field.
On the same page I also show a lost with the names of all my objects that i fetch from the database
Here is my code:
$object = self::getObjectById($objectId);
$objects = self::getAllObjects();
$objectForm = self::CreateObjectForm($object);
$objectFormForm->handleRequest($request);
dd($objects);
When I submit the form and I leave the name field open, It throws an error that the field is required when it reloads the page, the name field of the form is still empy wich is normal.
But here is the problem, in the list of objects that is also showing on this page the name of the object I tried to update has no name showing anymore in this list.
I don't know why this is happening since i fetched this list of objects completely seperatly from the form object. When I dd() the objects after the handleRequest() I cans see in the dumped vars that indeed the name field is empty. When i check the database, the name field is not empty and still holds the old name. Wich makes sence because the object is not persisted and flushed to de db. When I dd() the same list before the handleRequest() everything is normal.
How can I prevent this behaviour? And why is this happening?