ralphmorris/exporter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ralphmorris/exporter

Composer 安装命令:

composer require ralphmorris/exporter

包简介

Export a collection of models to csv

README 文档

README

Exporter is a package for Laravel that provides a simple csv export of any collection of models.

Installation

composer require ralphmorris/exporter

Usage

In your controller use:

use RalphMorris\Exporter\Exporter;

Then inside your method a simple call could look like:

public function export()
{
    $users = User::get();

    $exporter = new Exporter;

    return $exporter->exportToCsv($users);
}

You can also optionally specify the filename by providing a second parameter.

return $exporter->exportToCsv($users, 'my-file-name.csv');

Speciying which columns to export

If you only want to export certain columns from your model simply include the ExportableColumnsTrait trait in your model class and define a protected property of $exportableColumns with an array of the fields you would like to be exportable.

For example:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use RalphMorris\Exporter\ExportableColumnsTrait;

class User extends Model
{
    use ExportableColumnsTrait;

	/**
	 * The columns that are exportable to CSV
	 * 
	 * @var array
	 */
    protected $exportableColumns = [
        'name',
        'email',
    ];

Then in your query simply call the query scope exportableColumns() as per the below example.

public function export()
{
    $users = User::exportableColumns()->get();

    $exporter = new Exporter;

    return $exporter->exportToCsv($users);
}

统计信息

  • 总下载量: 44
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固