{"id":"9bc7253a285b8365","repo":"laravel/framework","slug":"add-fillable-property-s-to-allow-mass-assignmen","errorCode":null,"errorMessage":"Add fillable property [%s] to allow mass assignment on [%s].","messagePattern":"Add fillable property \\[(.+?)\\] to allow mass assignment on \\[(.+?)\\]\\.","errorType":"exception","errorClass":"MassAssignmentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Eloquent/Model.php","lineNumber":706,"sourceCode":"                if (isset(static::$discardedAttributeViolationCallback)) {\n                    call_user_func(static::$discardedAttributeViolationCallback, $this, [$key]);\n                } else {\n                    throw new MassAssignmentException(sprintf(\n                        'Add [%s] to fillable property to allow mass assignment on [%s].',\n                        $key, get_class($this)\n                    ));\n                }\n            }\n        }\n\n        if (count($attributes) !== count($fillable) &&\n            static::preventsSilentlyDiscardingAttributes()) {\n            $keys = array_diff(array_keys($attributes), array_keys($fillable));\n\n            if (isset(static::$discardedAttributeViolationCallback)) {\n                call_user_func(static::$discardedAttributeViolationCallback, $this, $keys);\n            } else {\n                throw new MassAssignmentException(sprintf(\n                    'Add fillable property [%s] to allow mass assignment on [%s].',\n                    implode(', ', $keys),\n                    get_class($this)\n                ));\n            }\n        }\n\n        return $this;\n    }\n\n    /**\n     * Fill the model with an array of attributes. Force mass assignment.\n     *\n     * @param  array<string, mixed>  $attributes\n     * @return $this\n     */\n    public function forceFill(array $attributes)\n    {","sourceCodeStart":688,"sourceCodeEnd":724,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Eloquent/Model.php#L688-L724","documentation":"Thrown by Model::fill() at the post-loop check: when the number of provided attributes differs from those accepted via fillableFromArray() AND preventsSilentlyDiscardingAttributes() is on. Unlike the per-key form, this fires once listing all keys that were entirely filtered out (e.g. because they were in $guarded). The message lists every discarded key and the class.","triggerScenarios":"Model::preventSilentlyDiscardingAttributes() is enabled globally and you call create()/fill()/update() with keys present in $guarded (or absent from a non-empty $fillable), so fillableFromArray() drops them and the counts diverge.","commonSituations":"Turning on strict mass-assignment discarding in dev/test; configuring $guarded with specific columns then attempting to mass-assign one of them; payloads from requests including guarded fields.","solutions":["Remove the offending keys from the input array before calling fill()/create() (e.g. via $request->only(...)).","Add the keys to $fillable (and remove from $guarded) if they should be mass-assignable.","Use forceFill() when intentionally bypassing guards for those specific keys.","Disable preventSilentlyDiscardingAttributes() in contexts where silent discard is acceptable."],"exampleFix":"// before\nModel::preventSilentlyDiscardingAttributes();\nUser::create($request->all()); // $request has guarded 'is_admin'\n\n// after\nUser::create($request->only(['name', 'email']));","handlingStrategy":"validation","validationCode":"$instance = new $modelClass;\n$accepted = $instance->fillableFromArray($input);\nif (count($input) !== count($accepted) && \\Illuminate\\Database\\Eloquent\\Model::preventsSilentlyDiscardingAttributes()) {\n    // some keys are guarded; restrict input before fill\n    $input = array_intersect_key($input, array_flip($instance->getFillable()));\n}\n$instance->fill($input);","typeGuard":null,"tryCatchPattern":"try {\n    $model->fill($input);\n} catch (\\Illuminate\\Database\\Eloquent\\MassAssignmentException $e) {\n    // log discarded keys, then forceFill or restrict input\n}","preventionTips":["Whitelist request input via $request->only($model->getFillable()).","Keep $guarded and $fillable consistent across model changes.","Turn on strict discarding in dev so surprises surface before prod."],"tags":["eloquent","mass-assignment","security","fillable","strict-mode"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}