Php 如何跳过有关使用Maatwebsite/laravel excel导入excel laravel的行

Php 如何跳过有关使用Maatwebsite/laravel excel导入excel laravel的行,php,excel,laravel,laravel-excel,Php,Excel,Laravel,Laravel Excel,我有一个问题要跳过关于使用Maatwebsite/laravel excel包导入excel laravel的行。 我在网上尝试了很多方法,但仍然不起作用 这是我的控制器代码 if ($request->hasFile('file')) { $import = new HsatuImport(); $file = $request->file('file'); //GET FILE // config(['excel.import.st

我有一个问题要跳过关于使用Maatwebsite/laravel excel包导入excel laravel的行。 我在网上尝试了很多方法,但仍然不起作用

这是我的控制器代码

if ($request->hasFile('file')) {
        $import = new HsatuImport();
        $file = $request->file('file'); //GET FILE
        // config(['excel.import.startRow' => 2]);
        Excel::import($import, $file)->limit(false, 2); //IMPORT FILE
        return redirect()->route('admin.hsatus.upload')->withFlashSuccess('Upload Berhasil '.$import->getRowCount().' Data');
    } else {
        return redirect()->route('admin.hsatus.upload')->withFlashSuccess('Upload Gagal');
    }
这是我的输入代码

<?php

namespace App\Imports;

use App\Models\Hsatu;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\ToModel;

class HsatuImport implements ToModel
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    private $rows = 0;
    public function model(array $row)
    {
        ++$this->rows;
        return new Hsatu([
            'region' => @$row[0],
            'nomor_faktur' => @$row[1],
            'nomor_rangka' => @$row[2],
            'kode_mesin' => @$row[3]
        ]);
    }

    public function headingRow(): int
    {
        return 1;
    }

    public function getRowCount(): int
    {
        return $this->rows;
    }
}


当已经存在雄辩的模型时,我有跳过的问题。下面是我的代码:

public function model(array $row)
    {
        $name = $row['name'];
        if (!Category::where('name', $name)->exists())
            return new Category([
                'name' => $name
            ]);
    }

只有当给定的语句为真时,我才返回模型实例。

当已经存在雄辩的模型时,我有跳过的问题。下面是我的代码:

public function model(array $row)
    {
        $name = $row['name'];
        if (!Category::where('name', $name)->exists())
            return new Category([
                'name' => $name
            ]);
    }
仅当给定的语句为true时,我才返回模型实例