Laravel-excel: [BUG] Error import: object beginTransaction

Created on 16 Jan 2019  ·  13Comments  ·  Source: Maatwebsite/Laravel-Excel

Prerequisites

  • [x] Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Excel.
  • [x] Checked that your issue isn't already filed.
  • [x] Checked if no PR was submitted that fixes this problem.

Versions

  • PHP version: 7.2
  • Laravel version: 5.7.17
  • Package version: 3.1.3

Description

I have created the import object class and specified the Concerns of ToCollection. Upon performing Excel::import, I receive an error shown in Actual Behavior below.

Steps to Reproduce

Do not use a transactional database. We use MongoDB.

Aside from that, Model importing was not specified and the package should not be doing any database preparation, that should be handled through events by the developer.

Expected behavior:

dd of the collection rows.

Actual behavior:

1) Tests\Unit\Services\Websites\WebsiteCredentialsImportServiceTest::testImportTabDelimited
Error: Call to a member function beginTransaction() on null

/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:109
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:93
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:23
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:327
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:223
/var/www/vhosts/website.local/vendor/maatwebsite/excel/src/Reader.php:96
/var/www/vhosts/website.local/vendor/maatwebsite/excel/src/Excel.php:120
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:223
/var/www/vhosts/website.local/app/Services/Websites/WebsiteCredentialsImportService.php:198
/var/www/vhosts/website.local/app/Services/Websites/WebsiteCredentialsImportService.php:182
/var/www/vhosts/website.local/app/Services/Websites/WebsiteCredentialsImportService.php:122
/var/www/vhosts/website.local/tests/Unit/Services/Websites/WebsiteCredentialsImportServiceTest.php:25

Additional Information

<?php

namespace App\Imports\Websites;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;

/**
 * Class WebsiteCredentialsImport
 *
 * @package App\Imports\Websites
 */
class WebsiteCredentialsImport implements ToCollection
{
    public function collection(Collection $rows)
    {
        dd(['COLLECTION' => $rows]);
    }
}
        $collection = Excel::import(
            new WebsiteCredentialsImport,
            $this->file_name,
            null,
            $this->reader_type
        );
enhancement help wanted

Most helpful comment

Maybe you guys are having the same issue I did at #2384

Maybe my solution would work for you, try a:

php artisan config:clear

Sometimes, specially when updating a package, Laravel won't clean the cache and your package won't find the config files. Thus, the driver will be always NULL and fail.

All 13 comments

We use the database transactions for validation and batch inserts. They are quite vital for the Eloquent/Laravel-DB users. Happy to merge a PR that gives a config option to disable it for users that use .e.g Mongo

Next version will have a setting to disable Laravel-DB transactions + a way to add custom transaction handlers

Hi !

I'm in the very exact situation: I need to NOT save read data, and I am using Mongo.

Could you point me please to the code that disable transactions?

Hi !

I'm in the very exact situation: I need to NOT save read data, and I am using Mongo.

Could you point me please to the code that disable transactions?

https://github.com/Maatwebsite/Laravel-Excel/commit/13374dab1592f00f715fa0e02541ecb52217655b#diff-19c82312ec0dbaba6a8c595db14fa56f

Relevant documentation section: https://docs.laravel-excel.com/3.1/imports/validation.html#disable-transactions

Hi, I'm in the same situation: I have to read an excel file and I need to store it in mongodb.
I've read the fix and the error I have now is:
"Unable to resolve NULL driver for [MaatwebsiteExcel\Transactions\TransactionManager]."
Do you have any idea how to solve it?
Thank you for the great package.

edit: I used the import to collection and it works, but I still don't knonw why the import toModel breaks

Because Collection doesn't use transactions. Please refer to my previous comment, it explains how to disable transactions.

Because Collection doesn't use transactions. Please refer to my previous comment, it explains how to disable transactions.

Hi, thank you for your quick reply.
I did read your comment, that's why I recieved the "Unable to resolve NULL driver for [MaatwebsiteExcel\Transactions\TransactionManager]." error.
So I switched to collection

You are probably typing something wrong in your config then. NULL doesn't sound like a valid driver. 'null' (note that it is a string) is.

I also have the same situation, I got the solution on https://docs.laravel-excel.com/3.1/imports/validation.html#disable-transactions
But, I don't know how to create Custom transaction handlers and where to use it

I have mongodb too. this https://docs.laravel-excel.com/3.1/imports/validation.html#disable-transactions works for me. Thx @patrickbrouwers

Maybe you guys are having the same issue I did at #2384

Maybe my solution would work for you, try a:

php artisan config:clear

Sometimes, specially when updating a package, Laravel won't clean the cache and your package won't find the config files. Thus, the driver will be always NULL and fail.

Maybe you guys are having the same issue I did at #2384

Maybe my solution would work for you, try a:

php artisan config:clear

Sometimes, specially when updating a package, Laravel won't clean the cache and your package won't find the config files. Thus, the driver will be always NULL and fail.

Best Answer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rossjcooper picture rossjcooper  ·  3Comments

contifico picture contifico  ·  3Comments

octoxan picture octoxan  ·  3Comments

vandolphreyes picture vandolphreyes  ·  3Comments

bahmanyaghoobi picture bahmanyaghoobi  ·  3Comments