Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

laravel eloquent update or create

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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
]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading