Since Flarum 2, passing an array of attributes straight into a model constructor or fill() raises a 500 rather than silently ignoring unguarded attributes.
Wrong
$thing = new Thing($attributes); // or $thing->fill($request->getParsedBody()['data']['attributes']);
Right
Assign properties explicitly. It is more code and it is also the only version that survives a schema change without quietly writing a column you did not intend:
$thing = new Thing(); $thing->title = $attributes['title']; $thing->body = $attributes['body']; $thing->save();
The same applies to relationships and to any helper that forwards an attribute array into a model.
Recommended Comments