Monday, December 23, 2019

Maatwebsite Laravel-Excel document

https://docs.laravel-excel.com/3.1/imports/collection.html

Importing to collections
The easiest way to start an import is to create a custom import class. We'll use a user import as example.

Create a new class called UsersImport in app/Imports:

namespace App\Imports;

use App\User;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;

class UsersImport implements ToCollection
{
    public function collection(Collection $rows)
    {
        foreach ($rows as $row)
        {
            User::create([
                'name' => $row[0],
            ]);
        }
    }
}

1 comment: