관리-도구
편집 파일: ProviderImport.php
<?php namespace App\Imports; use App\Models\Provider; use Illuminate\Validation\Rule; use Maatwebsite\Excel\Concerns\ToModel; use Maatwebsite\Excel\Concerns\WithHeadingRow; use Maatwebsite\Excel\Concerns\WithValidation; use DB; class ProviderImport implements ToModel, WithHeadingRow, WithValidation { public function model(array $row) { return new Provider([ 'name' => $row['name'], 'code' => $this->getNumberOrder(), 'adresse' => $row['address'] ?? null, 'phone' => $row['phone'] ?? null, 'email' => $row['email'] ?? null, 'country' => $row['country'] ?? null, 'city' => $row['city'] ?? null, 'tax_number' => $row['tax_number'] ?? null, ]); } public function rules(): array { return [ '*.name' => ['required', 'string', 'max:255'], ]; } private function getNumberOrder() { $last = DB::table('providers')->latest('id')->first(); return $last ? $last->code + 1 : 1; } }