尝试导入XLS时出现以下错误
Unable to resolve NULL driver for [Maatwebsite\Excel\Transactions\TransactionManager].
要导入的代码是:
Excel::import(new ProdutosImport, $file)
实际的导入是
<?php
namespace App\Imports;
use App\Produto;
use Maatwebsite\Excel\Concerns\OnEachRow;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
class ProdutosImport implements OnEachRow, WithHeadingRow
{
/**
* <strong i="27">@param</strong> array $row
*
* <strong i="28">@return</strong> \Illuminate\Database\Eloquent\Model|null
*/
public function onRow($row)
{
$row = $row->toArray();
if ($row['nmero_do_pedido'] !== null && $row['sku'] !== null) {
$produto = Produto::firstOrNew(['id_venda' => $row['nmero_do_pedido'], 'sku' => $row['sku'], 'sequeencia' => null]);
$produto->id_venda = $row['nmero_do_pedido'];
$produto->sequeencia = null;
$produto->sku = $row['sku'];
$produto->data_pagamento = $row['data_de_pagamento'];
$produto->estado_pagamento = $row['status_do_pagamento'];
$produto->titulo_produto = $row['nome_do_produto'];
$produto->sub_total = $row['valor_do_produto'];
$produto->descuento_compra = 0;
$produto->total_venda = $row['valor_do_produto'];
$produto->save();
}
}
}
预期行为:
导入文件。
实际行为:
错误出在Unable to resolve NULL driver for [Maatwebsite\Excel\Transactions\TransactionManager].
即使我没有使用Mongo,我也尝试按照#1998的建议禁用事务,但是它什么也没有改变。
您是否在https://github.com/Maatwebsite/Laravel-Excel/issues/1998#issuecomment -508995478中尝试了我的答案? 听起来您使用的配置值错误。
顺便说一句, @patrickbrouwers ,无论我使用'db'还是'null'作为'handler'的值,我都会得到相同的消息'Unable to resolve NULL driver'
我遇到了这个问题,我的问题是我使用的是库而不添加配置文件excel.php
。
所以我通过清除缓存来跟踪它(并且它起作用了),然后我添加了配置文件,然后再次缓存了我的配置。
我希望这有帮助。
最有用的评论
好的,我做了一些调查,这不是错误。
Laravel缓存正在软件包读取新发布的供应商配置的方式中。
一个简单的php artisan config:clear做到了。