Laravel CSV使用相同ID导入插入(简单导入)

This is my store method which grabs the file and loops through each of the rows:

public function store()
    {
        $input = Input::file('statuses');
        $filename = $input->getRealPath();
        $i = 0;

        $rows = Excel::load($filename, null, 'ISO-8859-1')->get()->toArray();

        foreach($rows as $k => $row)
        {
            if(!isset($err)) {
                if (!$this->repository->create($row))
                    $err = 'Error importing row ' + $i;
                    $i++;
                }
        }

        if(isset($err)) {
            Flash::error($err);
            return Redirect::route('admin.importstatus.index');
        }

        Flash::success('Statuses Imported!');
        return Redirect::route('admin.statuses.index');
    }

In my repository, my create method looks like this:

public function create(array $data)
{
    // Create the model
    $model = $this->model->fill($data);

    if ($model->save()) {
        return $model;
    }

    return false;
}

Now, what appears to be happening when I import 6 rows only the final is actually getting inserted into the DB.

If I var_dump in my create method, I am being returned the following:

    array (size=7)
  'content' => string 'Imported two' (length=12)
  'status' => float 0
  'user_id' => float 1
  'pinned' => float 0
  'updated_at' => string '2015-06-28 16:13:22' (length=19)
  'created_at' => string '2015-06-28 16:13:22' (length=19)
  'id' => int 8
array (size=7)
  'content' => string 'Imported three' (length=14)
  'status' => float 0
  'user_id' => float 1
  'pinned' => float 0
  'updated_at' => string '2015-06-28 16:13:22' (length=19)
  'created_at' => string '2015-06-28 16:13:22' (length=19)
  'id' => int 8
array (size=7)
  'content' => string 'Imported four' (length=13)
  'status' => float 0
  'user_id' => float 1
  'pinned' => float 0
  'updated_at' => string '2015-06-28 16:13:22' (length=19)
  'created_at' => string '2015-06-28 16:13:22' (length=19)
  'id' => int 8

Notice how each of the ID's are all no. 8 (The next available row in the table). The tables ID is defo AUTO INCREMENT etc so no issues there, I guess its a logic issue? Any ideas?

Seems like you are using the same instance of a model over and over.

Try changing fill():

$this->model->fill($data);

with create():

$this->model->create($data);

With fill() you are only filling the already created model instance with some data. But if you use create() you are first creating a new instance (with a new id), then filling it with data and then saving it.

Important

When using create() you are also persisting it to the database, which means you don't have to save() it manually.