1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Imports;
- use App\Http\Models\Business;
- use App\Http\Models\LinkCase;
- use Illuminate\Support\Collection;
- use Maatwebsite\Excel\Concerns\Importable;
- use Maatwebsite\Excel\Concerns\ToCollection;
- class ExternalCaseImport implements ToCollection
- {
- use Importable;
- public function collection(Collection $collections)
- {
- $linkType = array_flip(LinkCase::TYPES);
- $list = [];
- foreach ($collections as $key => $collection) {
- if ($key < 1) {
- continue;
- }
- $data = [
- 'type' => $linkType[$collection[0]],//对不上直接抛异常
- 'url' => $collection[1] ?? '',
- 'username_history' => $collection[2] ?? '',
- 'email_history' => $collection[3] ?? '',
- 'password_history' => $collection[4] ?? '',
- 'url_history' => $collection[5] ?? '',
- 'created_at' => date('Y-m-d H:i:s')
- ];
- $list[] = $data;
- }
- LinkCase::query()->insert($list);
- }
- }
|