承接 rikless/xporter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

rikless/xporter

Composer 安装命令:

composer require rikless/xporter

包简介

CSV wrapper to export eloquent query result

关键字:

README 文档

README

Xporter is a CSV wrapper allowing you to export Eloquent query results from your laravel application, using league/csv package. With help of Laravels Xporter class creates exportable schema that can be easy modified and reused.

Documentation

Installation

Run:

composer require rikless/xporter:1.*

Example usage

Create a simple class where you'll have all your export parameter anywhere in your application. App\Exports may be a good place to start. You'll need to extend the Rikless\Xporter\Exportable class.

Now complete convert(), query() methods and xportable, rootModel properties.

You have to use the convert() methods to transform your data, and add data from relationship.

In your query method, you just need to instantiate your model and add your query. It can be anything from a Request object in your controller. Be aware to not use the get() or all() method in you query, because the package will chunk results. This mean that it needs an Illuminate\Database\Eloquent\Builder object.

<?php

namespace App\Exports;

use Rikless\Xporter\Exportable;
use Carbon\Carbon;
use Illuminate\Http\Request;

class UsersExporter extends Exportable
{

    protected $xportable = ['email', 'uuid'];

    protected $rootModel = \App\User::class;

    public function convert($item)
    {
        return [
            'email' => $item->email,
            'uuid' => $item->name,
        ];
    }

    public function query(Request $request)
    {
        return (new $this->rootModel)->where('created_at', '<=', Carbon::now());
    }

}

And now in your controller :

<?php

namespace App\Http\Controllers;

use App\Exports\UsersExporter;
use Illuminate\Http\Request;

class TestController extends Controller
{
    public function store(UsersExporter $usersExporter, Request $request)
    {
        return $usersExporter->build($request);
    }
}

License

Licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固