123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App\Imports;
- use App\Model\PhoneInfo;
- use Maatwebsite\Excel\Concerns\ToModel;
- use Maatwebsite\Excel\Concerns\WithStartRow;
- use Maatwebsite\Excel\Concerns\Importable;
- use Maatwebsite\Excel\Concerns\WithValidation;
- class PhoneImport implements ToModel,WithStartRow,WithValidation
- {
- use Importable;
- /**
- * @param array $row
- *
- * @return \Illuminate\Database\Eloquent\Model|null
- */
- public function model(array $row)
- {
- return new PhoneInfo([
- 'phone' => $row[0]
- ]);
- }
- // 从2行开始读取数据
- public function startRow(): int
- {
- return 2;
- }
- // 验证
- public function rules(): array
- {
- return [
- '0' => 'required',
- ];
- }
- }
|