Form::checkbox() not working with relationship and empty model.
borfast opened this issue · 1 comments
In the spirit or "DRY" I am reusing a form for one of my models for both editing existing entries and creating new ones. This form is being created via Form::model().
The model has a many-to-many relationship with another model. A possible analogy to my case is to think of it as an Employee
model and an Office
model, where the Employee
can be assigned to various Office
s.
On the aforementioned form, where a new Employee
can be created or an existing one edited, there are checkboxes to allow the user to assign Office
s to the Employee
. These checkboxes should obviously be unchecked if a new Employee
is being created but they are all checked instead.
Even worse is that when I edit an existing Employee
that is assigned to an Office
, all checkboxes are still checked instead of only the correct Office
being checked.
I'm sure this is not the expected behavior and I'm quite amazed that no one else has bumped into this issue so far (couldn't find anything about it), since it's a pretty common use case.
Any thoughts on how to fix it?
EDIT: Actually, I did find one reference to the same issue: http://forums.laravel.io/viewtopic.php?pid=54712
Seems to be the exact same problem and it proposes a solution.
I just added a pull request using the solution from the forum post linked above that fixes the issue.