Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 weeks ago.
0

you can unset that property in the model event saving

laravel.com/docs/eloquent#model-observers

Last updated 2 weeks ago.
0

Try to explicitly declare the variable in your User class, e.g.

class User extends Eloquent {

    ...

    public $suspicious = false; //a default value

    ...

}

In this case, __set() shouldn't be executed for the declared variable, which therefore wouldn't be added to the $attributes array (note that only the items contained in the $attributes array will be saved).

PS: IMO, Laravel should really provide a "transient" and a "persistent" array the same way it provides the fillable/guarded ones. Do you have time for a pull request?

Last updated 2 weeks ago.
0

I think I tried explicitly declaring the property and it still tried to save it to the database, but I was very tired when I was working last night so I will try again.

I did manage to extend Model and I think it only requires a simple change to getDirty() to check if the key is set in a transient array. So when I get home I will do a pull request for that change if it turns out explicit declaration doesn't work.

zenry, great suggestion, I think that will be a good fallback solution.

Edit: quick update. The problem I had before was that I simply didn't initialize the property with a default as was suggested. Giving it a default kept it out of the attributes for saving it in the database, so this has resolved the issue.

Last updated 2 weeks ago.
0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

Moderators

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

Your logo here?

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

© 2022 Laravel.io - All rights reserved.