ShawnMcCool / laravel-form-base-model

A base model for forms.
97 stars 13 forks source link

get method nulls 0 value #14

Open alexleonard opened 11 years ago

alexleonard commented 11 years ago

Hey Shawn,

I've just encountered an issue using ::get().

I have a form model called RegistrationForm

In step one post I do a sample:

RegistrationForm::set('test', 0);

Then in step two get I run:

var_dump(RegistrationForm::all());
var_dump(RegistrationForm::get('test'));

And that outputs

array(1) {
    ["test"]=>int(0)
}

NULL

This causes me an issue using either bool or int inputs on the registration form. I can get around it at the moment by assigning RegistrationForm::all() to a variable and just picking the values from there, but it looked like an issue to me so I thought I'd post it here.

Cheers! Alex

ShawnMcCool commented 11 years ago

This may be due to the falsey check on this line https://github.com/ShawnMcCool/laravel-form-base-model/blob/master/base.php#L309

If you remove static::$field_data[$class_name]->$field_name it may work, or it may break other things.

I'm sorry, I'm not really sure. Just now I removed this package from the bundles site, and I put a disclaimer in the README file. People can still find the code here. While the model does improve working with forms in L3. I think that someone could easily write a much better model than this, something tested that doesn't contain static state. I wrote this in an awkward transitional time.