kiessan
1 week ago
21
0
Nova

Saving "virtual" Field to related model

Posted 1 week ago by kiessan

I am fairly new to Nova and trying to save a "virtual" Field to a related model. I need to do this, because I have to update tables on an external database connection, where the DB schema can't be changed.

In the database there is a customer table and customer_attributes table. In the related table there is exactly one row for each customer. The columns are called attr_1 etc.

In my Customer Resource I added a field:

Text::make('referrerCode');

The creation of the model fails since there is no column referrer_code on the customer table. However, I need to store the value in the attr_1 column of the related row.

Therefore I need to created a related attributes entry, if not yet existent, and store the referrer_code in it. Additionally I have to prevent Eloquent from trying to save the referrer_code.

Would we cool if anybody could point me into the right direction. Cheers.

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