Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

HarshaReddy's avatar

laravel 6.0 maatwebsite excel 3.1 import

Please, how to import excel data to database in maatwebsite excel 3.1 version?Thanks in advance

0 likes
6 replies
HarshaReddy's avatar

I want import my data to another table, not to users table!

Nakov's avatar

@harshareddy :D Then you use your other table.. Pretty simple. Those are just examples, being a programmer requires you to know how to use an example and apply it to your codebase.

1 like
drewdan's avatar

The examples all seem to use User as the model or table - probably because Laravel has the Auth Scaffolding so most Laravel applications will likely use it so its a good model to use as an example

As @nakov said, follow the example and if you get stuck, come ask us for help with an example of your code and where you got stuck. :)

Sinnbeck's avatar

Just a quick example. Replace MyModel with the actual model and the name/type/status with the actual column names :)

<?php

namespace App\Imports;

use App\MyModel;
use Illuminate\Support\Facades\Hash;
use Maatwebsite\Excel\Concerns\ToModel;

class MyModelImport implements ToModel
{
    /**
     * @param array $row
     *
     * @return MyModel|null
     */
    public function model(array $row)
    {
        return new MyModel([
           'name'     => $row[0],
           'type'    => $row[1],
           'status' => $row[2],
        ]);
    }
}

Please or to participate in this conversation.