LaravelCollective / docs

Documentation for LaravelCollective Packages
158 stars 103 forks source link

Inconsistency in form model accessors documentation #26

Closed gmhenderson closed 6 years ago

gmhenderson commented 8 years ago

The documentation regarding form model accessors (https://laravelcollective.com/docs/5.2/html#form-model-accessors) does not match the implementation in the code. Currently, the getModelValueAttribute() method in FormBuilder.php, looks for a model method called getFormValue() whereas the documentation says to create a model method like formMyAttribute(). Does the documentation need to be updated to match the code or vice versa?

For what it's worth, I think I like the format suggested by the docs better than what the code currently implements. Having a single getFormValue() method requires a bunch of conditionals to figure out which attribute to return; using multiple methods seems cleaner. Then again, once could implement a number of protected methods called by getFormValue()...

I can submit a PR with either fix. And thanks for the work you've put into this package, it's been a pleasure to work with.

st3f commented 8 years ago

+1 (just figured out the same problem)

my quick and dirty fix:

if (method_exists($this->model, 'form' . Str::studly($key) . 'Attribute')) {
        $value = $this->model->{$key};

       return $this->model->{'form' . Str::studly($key) . 'Attribute'}($value);
}
alexanderawitin commented 8 years ago

+1

redgluten commented 8 years ago

Not sure about this one, because right now the formMyAttribute is working correctly if you use the FormAccessible trait: is this issue relevant to an outdated version or is there more to it? Any ideas @tshafer @adamgoose ?