Home > Blockchain >  laravel eloquent update or create
laravel eloquent update or create

Time:02-04

Hi i'm using this to insert or update a record based on 3 values :

DynamicTable::updateOrCreate(
                [
                    'component_id' => $getComponentMainId->id, 
                    'generated_workflow_id' => $created_generated_form['id'], 
                    'form_id'=> $form_id,
                ],
                [
                    'number_of_rows', $mainRows,
                    'row_indexes' => $indexes
                ]
            );

if record found it will update the number of rows and the indexing otherwise it insert all fields, but the problem is it create or update only the row_indexes without adding or updating number_of_rows allthough all fields are listed in protected $fillable. Both queries are :

bindings: (3) [3709, 52, 316]
query: "select * from `dynamic_tables` where (`component_id` = ? and `generated_workflow_id` = ? and `form_id` = ?) and `dynamic_tables`.`deleted_at` is null limit 1"

and

bindings: (6) [3709, 52, 316, '0,2', '2022-02-04 10:48:34', '2022-02-04 10:48:34']
query: "insert into `dynamic_tables` (`component_id`, `generated_workflow_id`, `form_id`, `row_indexes`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?)"

is there something that i didn't pay attention for it

CodePudding user response:

You have error in your syntax:

'number_of_rows', $mainRows

I assume should be:

'number_of_rows' => $mainRows
DynamicTable::updateOrCreate([
        'component_id' => $getComponentMainId->id, 
        'generated_workflow_id' => $created_generated_form['id'], 
        'form_id'=> $form_id,
    ],[
        'number_of_rows' => $mainRows,
        'row_indexes' => $indexes
]);
  •  Tags:  
  • Related