2 months ago

Save object ignoring extra columns

Posted 2 months ago by karnax

How can I have an object update in the database regardless of what is in it? For example, if I have first_name and last_name in my database, I pull that record and create a "full_name" variable. I can't call save(). It looks like I might be able to exclude that column, but that is backwards. What if I want to create a "billing_address" field to display based on multiple fields. Or I make the field "current_page" to track what they are on while logged in but I don't want to save it in a database column. Isn't there a way to call save() and have it only save for the correct columns instead of throwing the error:

//Adding a user $user = User::create($userData);

//User last name changes $user->last_name = "newmarriedname"; $user->current_name = $user->first_name." ".$user->last_name;


SQLSTATE[42S22]: Column not found: 1054 Unknown column 'current_name' in 'field list'

This is just an example, so please don't get lost in the details of how to handle a name change. I have various fields and things I want to generate in my application that I don't want or need saved to the database but I do need some items saved or updated. These fields might change so I don't want to create a list of exclusions that need to be managed.


Please sign in or create an account to participate in this conversation.