0

I get the message Call to a member function beginTransaction() on null when importing data from "Maatwebsite\Excel\Excel" using laravel 8.0 and MongoDB. Export is ok, I've already tried to set transaction handler to 'null' and php artisan config:clear and php artisan config:cache but with no luck. here's my controller

public function store(UserLoadRequest $request)
    {
        $request->authorize();
        $validated = $request->validated();
        //dd($request->file('usersList'));
        //dd($validated['usersList']->getPathname());
        Excel::import(new UsersImport, $request->file('usersList'));

        return redirect()->back()->with('success', 'Utenti caricati');
    }

and here my import function

class UsersImport implements ToModel, WithHeadingRow
{
    public function model(array $row)
    {
        return new User([
            'descrizione'  => $row['descrizione'],
            'username'  => $row['username'],
            'password'  => Hash::make($row['password']),
            'meccanografico'  => $row['meccanografico'],
            'role_id'  => $row['role_id'],

        ]);
    }
}
Daitarn
  • 109
  • 1
  • 15

1 Answers1

1

The mongo db driver does not support transactions. Disable them in the config file. First publish it with php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config and then change the handler

'transactions' => [
        'handler' => 'null', //was db. Set to null
    ],

Solution Source link

AhmedxHs
  • 31
  • 6