Support the ongoing development of Laravel.io →
Database Eloquent Configuration
Last updated 1 year ago.
0

Bump? Can anyone help?

0

Seems like your $fillables is empty. Are you sure it's properly set up in Settings model? Could you show its code?

0

yeah i was about to ask the same question, re: code for the Settings model.. because that create() query only updates/inserts the date columns, nothing else.

0

Yes, I'm sure - the code looks like this:

protected $fillable = [ 'user_id', 'lang', 'date_format', 'per_page', 'dashboard_history', 'email_newsletters' ];

That's valid syntax as I've used it a ton of projects prior to this one.

shez1983 - What do you mean that create statement updates/inserts the date columns, nothing else? The statement below has the exact same result and it definitely updates all the columns:

Setting::create( [
    'user_id' => 1,
    'lang' => 'en',
    'date_format' => 'Y-m-d',
    'per_page' => 10,
    'dashboard_history' => 3,
    'email_newsletters' =>
] );
0

PovilasKorop said:

Seems like your $fillables is empty. Are you sure it's properly set up in Settings model? Could you show its code?

And just to make sure - documentation says it is $fillable, not $fillables.

0

I believe the error message indicates that $setting has no values in it which is why only the created_at and updated_at fields are shown in your SQL statement.

Did you do a dd($setting) to make sure the array you are passing into the create() method is what you think it is? It seems obvious that it should be correct but you never know until you look.

0

What i mean is that eloquent query is doing this:

[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into sio_settings (updated_at , created_at) values (2015-08-08 19:30:33, 2015-08-08 19:30:33))

so you see how it is ONLY doing insert into (date_columns).. and not USING anything else? this could be due to fillable.. but can you post the whole MODEL class please? and the related controller method?

0

PovilasKorop said:

Seems like your $fillables is empty. Are you sure it's properly set up in Settings model? Could you show its code?

I'm so glad I stumbled across this thread, was rushing through some code to do a quick fix on a DB and missed out one column in the $fillable array. Thank you @PovilasKorop!

0

smadeira said:

I believe the error message indicates that $setting has no values in it which is why only the created_at and updated_at fields are shown in your SQL statement.

Did you do a dd($setting) to make sure the array you are passing into the create() method is what you think it is? It seems obvious that it should be correct but you never know until you look.

Yep, I've run dd so many times I'm surprised I'm still allowed to use it. :-P

0

Are you trying to submit with empty inputs?

If so, It could be because "allow null" in your database isn't set on each field. I had the same issue and looked at my table and turned on allow null on all the fields in my database gui applications.

0

I stumbled across this too. And I found the answer to my problem is the Mutator.

It took me a while to figure out what happened.

####wrong way to implement Mutator:

public function setFirstNameAttribute($value)
{
    // do stuff
    return $value;
}

####right way:

public function setFirstNameAttribute($value)
{
    // do stuff
    $this->attributes['first_name'] = $value;
}

Since I kept returning stuff instead of really changing the attribute, the attribute would remain empty.

I hope this will help.

Last updated 7 years ago.
0

I had the same problem in Laravel 5.3 . In my case I changed the config/database.php file updating the value of 'strict' to false and it worked properly.

0

ralanyo said:

Are you trying to submit with empty inputs?

If so, It could be because "allow null" in your database isn't set on each field. I had the same issue and looked at my table and turned on allow null on all the fields in my database gui applications.

Thank you this was my issue! I wanted a default value of 0 for a column, laravel did this by default in 5.2 but for 5.4 I have to set it myself:

$table->bigInteger('num_visits')->default(0);

0

dakaizou said:

I stumbled across this too. And I found the answer to my problem is the Mutator.

@dakaizou Thank you! That was my issue.

0

The reason this is happening now, however, is that Laravel 5.1 uses strict mode for MySQL by default.

If you would like to revert to previous behavior, update your config/database.php file and set 'strict' => false for your connection.

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.