import chunk reading
This commit is contained in:
		| @@ -2,48 +2,19 @@ | ||||
|  | ||||
| namespace App\Imports\Banking; | ||||
|  | ||||
| use App\Abstracts\Import; | ||||
| use App\Models\Banking\Transaction as Model; | ||||
| use App\Http\Requests\Banking\Transaction as Request; | ||||
| use Maatwebsite\Excel\Concerns\ToModel; | ||||
| use Maatwebsite\Excel\Concerns\WithHeadingRow; | ||||
| use Maatwebsite\Excel\Concerns\WithMapping; | ||||
| use Maatwebsite\Excel\Concerns\WithValidation; | ||||
| use Maatwebsite\Excel\Validators\Failure; | ||||
|  | ||||
| class Transactions implements ToModel, WithHeadingRow, WithMapping, WithValidation | ||||
| class Transactions extends Import | ||||
| { | ||||
|     public function model(array $row) | ||||
|     { | ||||
|         return new Model($row); | ||||
|     } | ||||
|  | ||||
|     public function map($row): array | ||||
|     { | ||||
|         $row['company_id'] = session('company_id'); | ||||
|  | ||||
|         // Make reconciled field integer | ||||
|         if (isset($row['reconciled'])) { | ||||
|             $row['reconciled'] = (int) $row['reconciled']; | ||||
|         } | ||||
|  | ||||
|         return $row; | ||||
|     } | ||||
|  | ||||
|     public function rules(): array | ||||
|     { | ||||
|         return (new Request())->rules(); | ||||
|     } | ||||
|  | ||||
|     public function onFailure(Failure ...$failures) | ||||
|     { | ||||
|         foreach ($failures as $failure) { | ||||
|             $message = trans('messages.error.import_column', [ | ||||
|                 'message' => $failure->errors()->first(), | ||||
|                 'sheet' => 'transactions', | ||||
|                 'line' => $failure->attribute(), | ||||
|             ]); | ||||
|      | ||||
|             flash($message)->error()->important(); | ||||
|        } | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user