Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] MassAssignmentException JSON error output not explicit for non-fillable fields #21042

Closed
rgehan opened this issue Sep 6, 2017 · 2 comments

Comments

@rgehan
Copy link
Contributor

rgehan commented Sep 6, 2017

  • Laravel Version: 5.5.2
  • PHP Version: PHP 7.1.3 (cli) (built: Apr 4 2017 18:40:27) ( NTS )
  • Database Driver & Version: 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:

{
    "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
@rgehan 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
@themsaid
Copy link
Member

themsaid commented Sep 6, 2017

Here's an attempt to make it look more informative: #21043

@themsaid themsaid closed this as completed Sep 6, 2017
@rgehan
Copy link
Contributor Author

rgehan commented Sep 6, 2017

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants