You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Model::create, if a non-fillable field is used, an error is returned.
The standard HTML output tells it is a MassAssignmentException which is quite explicit.
However when expecting a JSON response, the error output is unclear. It looks like that:
{
"message": "title",
"file": "/Users/rgehan/Sites/laravel-preset-react/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php",
"line": 237,
"trace": [
{
"file": "/Users/rgehan/Sites/laravel-preset-react/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php",
"line": 157,
"function": "fill",
"class": "Illuminate\\Database\\Eloquent\\Model",
"type": "->",
"args": [
{
"title": "This is the title",
"content": "Etiam natoque fusce dis euismod dolor condimentum egestas parturient fermentum, sociis habitasse libero nam adipiscing cubilia scelerisque enim dignissim pulvinar, aliquam ad convallis in mollis quisque proin praesent."
}
]
},
{
"file": "/Users/rgehan/Sites/laravel-preset-react/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php",
"line": 280,
"function": "__construct",
"class": "Illuminate\\Database\\Eloquent\\Model",
"type": "->",
"args": [
{
"title": "This is the title",
"content": "Etiam natoque fusce dis euismod dolor condimentum egestas parturient fermentum, sociis habitasse libero nam adipiscing cubilia scelerisque enim dignissim pulvinar, aliquam ad convallis in mollis quisque proin praesent."
}
]
},
...
Nothing say in this error that it is a MassAssignmentException. The titlefield of the output is simply the field that is not fillable.
Steps To Reproduce:
Create a model with a field that is not fillable
Attempts to Model::create(['not_fillable_field' => 'abc', ...]); from a request with the header: Accept: application/json
The text was updated successfully, but these errors were encountered:
rgehan
changed the title
[5.5] JSON error output not explicit when using model::create on a non-fillable field
[5.5] MassAssignmentException JSON error output not explicit for non-fillable fields
Sep 6, 2017
5.5.2
PHP 7.1.3 (cli) (built: Apr 4 2017 18:40:27) ( NTS )
10.1.19-MariaDB
Description:
When using
Model::create
, if a non-fillable field is used, an error is returned.The standard HTML output tells it is a
MassAssignmentException
which is quite explicit.However when expecting a JSON response, the error output is unclear. It looks like that:
Nothing say in this error that it is a
MassAssignmentException
. Thetitle
field of the output is simply the field that is not fillable.Steps To Reproduce:
Model::create(['not_fillable_field' => 'abc', ...]);
from a request with the header:Accept: application/json
The text was updated successfully, but these errors were encountered: