import rules not applicable in map
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Abstracts;
|
||||
|
||||
use App\Traits\Import as ImportHelper;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Jenssegers\Date\Date;
|
||||
use Maatwebsite\Excel\Concerns\Importable;
|
||||
@@ -15,6 +16,7 @@ use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithValidation;
|
||||
use Maatwebsite\Excel\Validators\Failure;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
abstract class Import implements ToModel, SkipsOnError, SkipsOnFailure, WithBatchInserts, WithChunkReading, WithHeadingRow, WithMapping, WithValidation
|
||||
{
|
||||
@@ -87,4 +89,24 @@ abstract class Import implements ToModel, SkipsOnError, SkipsOnFailure, WithBatc
|
||||
{
|
||||
flash($e->getMessage())->error()->important();
|
||||
}
|
||||
|
||||
public function isNotValid($row)
|
||||
{
|
||||
return Validator::make($row, $this->rules())->fails();
|
||||
}
|
||||
|
||||
public function isEmpty($row, $fields)
|
||||
{
|
||||
$fields = Arr::wrap($fields);
|
||||
|
||||
foreach ($fields as $field) {
|
||||
if (!empty($row[$field])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user