Skip to content

Model $attributes gives error with Model::firstOrCreate() #32925

@tanthammar

Description

@tanthammar
  • Laravel Version: 7.11.0
  • PHP Version: 7.4.4
  • Database Driver & Version: MySql 5.7

Description:

model $attributes gives error when I try to use Model::firstOrCreate()

Steps To Reproduce:

I have this on a model:

    protected $attributes = [
        'invoicing' => [
            'calc_due_days_from' => 'invoice_date',
            'invoice_date_num_days' => 30,
            'before_start_num_days' => 48,
            'currency_code' => 'SEK',
            'currency_symbol' => 'kr',
            'invoice_note' => null,
            'inv_prefix' => null,
            'inv_suffix' => null,
            'inv_counter' => null,
            'cred_note' => null,
            'cred_prefix' => null,
            'cred_suffix' => null,
            'cred_counter' => null,
        ],
    ];

It works great with new Model but I get an error if I try to use firstOrCreate()

Error in TinkerWell

Argument 1 passed to Illuminate/Database/Grammar::parameterize() must be of the type array, string given, called in /Users/tina/Sites/bookons-api/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 866

Error in Horizon (I am trying to make a batch import)

ErrorException: json_decode() expects parameter 1 to be string, array given in /Users/tina/Sites/bookons-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:811

If I comment out the attributes I can use firstOrCreate() without any problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions