Skip to content

How to save one of my fields to a custom table? #1926

Discussion options

You must be logged in to vote

Like @haringsrob said, afterSave is a good place to make this operation. Eg.

// App\Repositories\YourRepository.php
public function afterSave($object, $fields)
{
        // Skip this logic on create 
        if(!$object->wasRecentlyCreated){
        
            // If you have a model for your table
            \App\Models\YourModel::where('reference_id', $object->id)
              ->update(['json_column', $fields['multiselect_data']]);
            
            // Or via DB facade
            \DB::table('table')
              ->where('reference_id', $object->id)
              ->update(['json_column', $fields['multiselect_data']]);
        }

        return parent::afterSave($object, $fields

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by adam-jones-net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants