【问题标题】:How to save the csv when i import it in Laravel当我在 Laravel 中导入 csv 时如何保存
【发布时间】:2020-06-11 21:42:40
【问题描述】:

我是 Laravel 的新手,我有一个导入列表页面(这个页面工作得很好),这个导入一些列表放到数据库中。但我也想保存这个列表。

这是我的代码(CsvImport.php):

<?php

namespace App\Imports;

use App\Product;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Illuminate\Support\Facades\Auth;

class CsvImport implements ToModel, WithHeadingRow
{
    public function model(array $row)
    {
        return Product::query()->forceCreate([
            'name'        => $row["name"],
            'description' => $row["description"],
            'category'    => $row["category"],
            'price'       => $row["price"],
            'image'       => 'no-image.jpg',
            'user_id'     =>  Auth::user()->id,
        ]);
    }
}

一些想法? :)

【问题讨论】:

  • 这个问题和 Excel 有什么关系???
  • @teylyn,我正在使用的作曲家调用 Laravel Excel,很抱歉,我将删除
  • 需要将数据保存到db吗?
  • 数据已经保存在db中,我只想保存文件csv
  • @Learner,数据已经保存在db中,我只想保存文件csv

标签: laravel laravel-5 eloquent laravel-excel


【解决方案1】:

我没有找到,但我认为最好不要保存。

【讨论】:

    猜你喜欢
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 2022-01-23
    • 2022-11-01
    • 1970-01-01
    相关资源
    最近更新 更多