mavinoo / laravelBatch

insert batch and update batch in laravel
MIT License
564 stars 118 forks source link

Does it work with laravel 9? Did not work with laravel 9 in my project. 🐛 #88

Closed bhojkamal closed 2 years ago

bhojkamal commented 2 years ago

Hello, I've been using mavinoo/laravelBatch for my one project. It was working with laravel 8 before. But now it is not working with laravel 9. I upgraded the same projects to Laravel 9.

I got 500 (Internal Server Error) for batch update.

my code in api controller is as below:

            $index = 'id';
            if ($request->currMed) :
                $medicationInst = new TeleMedication;
                $TelMedis = array_filter($request->currMed);
                batch()->update($medicationInst, $TelMedis, $index);
            // Batch::update($medicationInst, $TelMedis, $index);
            endif;

            if ($request->preMed) :
                $prescribedInst = new TelePrescribedMedication;
                $preMeds = array_filter($request->preMed);
                batch()->update($prescribedInst, $preMeds, $index);
            endif;

            if ($request->labInv) :
                $labInst = new TeleLabInvestigation;
                $labInvs = array_filter($request->labInv);
                batch()->update($labInst, $labInvs, $index);
            endif;

I received data as below.

currMed : [ { "id": 1, "tel_patient_id": 7, "drug_name": "ibrufen", "drug_unit": "tablet", "dosage": "1 day", "initiation_at": "2022-04-25" }, { "id": 2, "tel_patient_id": 7, "drug_name": "codopar", "drug_unit": "tab", "dosage": "3 days", "initiation_at": "2022-04-25" } ]

so why it is not working in Laravel 9? How can we fix this issue.

bhojkamal commented 2 years ago

In the readme or user guide it has told to use this line of code

Batch::update($userInstance, $value, $index);

But this is not working, but it is working with this below code

batch()->update($userInstance, $value, $index);

Why?

I corrected one error minor error on Batch.php as it is done on github repo 5 days ago, vendor\mavinoo\laravel-batch\src\Batch.php and now worked with this line batch()->update($userInstance, $value, $index); but not with this Batch::update($userInstance, $value, $index); why?

mavinoo commented 2 years ago

hi @bhojkamal reinstall package or update package to 2.3.4

insert

batch-insert

update

batch-update