定制 sukohi/eloquent-export 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

sukohi/eloquent-export

Composer 安装命令:

composer require sukohi/eloquent-export

包简介

A Laravel package that allows you to export data from database through Eloquent model.

README 文档

README

A Laravel package that allows you to export data from your database through Eloquent model. This package is maintained under Laravel 6.x.

Installation

Execute the following command.

composer require sukohi/eloquent-export:2.*

Your Eloquent model already has export() method after installation.

Usage

The simplest way

Call export() in your controller.
Only filename required.

$users = \App\User::get();

// csv
return $users->export('test.csv');

// xlsx
return $users->export('test.xlsx');

// xls
return $users->export('test.xls');

Select column

Downloading data will be narrowed with select() method.

$users = \App\User::select('id', 'name', 'email')->get();
$users->export('test.csv);  // Only id, name and email data.

Options

Rendering

You can change downloading data with key, dot-notation-key, null, callback(s) as follows.

$users = \App\User::get();
$options = [
    'render' => [
        'id', // $user->id
        'company.name', // $user->company->name
        null, // blank column
        function($user) {

            return $user->created_at->format('Y.m.d');

        }
    ]
];
return $users->export('test.xls', $options);

Encoding

You can specify an encoding to convert data just when downloading csv file.

$options = ['encoding' => 'sjis-win'];
return $users->export('test.csv', $options);

Additional data

$users = \App\User::get();
$options = [
    'prepend' => [
        ['header - 1', 'header - 2', 'header - 3']
    ],
    'append' => [
        ['footer - 1', 'footer - 2', 'footer - 3']
    ]
];
return $users->export('test.xls', $options);

License

This package is licensed under the MIT License.

Copyright 2019 Sukohi Kuhoh

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固