定制 mayconbordin/l5-fixtures 二次开发

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

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

mayconbordin/l5-fixtures

Composer 安装命令:

composer require mayconbordin/l5-fixtures

包简介

A fixtures package for Laravel 5

README 文档

README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Fixtures package for Laravel 5 with support for JSON, CSV, YAML and PHP files.

If you are seeding your database with fake data that can be easily generated, consider using the Model Factories.

But if you need to load data that can't be generated then this is your best choice.

Installation

In order to install Laravel 5 Fixtures, just add

"mayconbordin/l5-fixtures": "dev-master"

to your composer.json. Then run composer install or composer update.

Then in your config/app.php add

'Mayconbordin\L5Fixtures\FixturesServiceProvider'

in the providers array and

'Fixtures' => 'Mayconbordin\L5Fixtures\FixturesFacade'

to the aliases array.

If you are using Laravel 5.5, package will be automatically discovered, no need to edit config/app.php

Configuration

To publish the configuration for this package execute php artisan vendor:publish and a fixtures.php file will be created in your app/config directory.

Usage

By default the fixtures directory is /fixtures, inside it you should place the data files that will fill the database. The name of the file should be exactly the same as the name of the database table (e.g.: 'table_one.json'). Take a look at the two examples in the /tests_data directory.

To apply all fixtures to the database run

Fixtures::up();

If you only want to apply some fixtures, you can pass an array with the name of the fixtures you want to apply

Fixtures::up('table_one', 'table_two');

And to destroy the records in the database run

Fixtures::down();

The down method can also receive an array with the name of fixtures that will be destroyed. Currently all records in the database tables are destroyed.

If you haven't published the configuration file or you want to load fixtures from another location, you only need to execute the following code before applying the fixtures:

Fixtures::setUp('/path/to/fixtures');

Data Format

The fixtures files are parsed in order to create an array of records that are themselves associative arrays. The resulting array is then inserted in the database using the insert method of the query builder.

Relations are not handled by the library, but you can make reference to other records by their IDs, even if they haven't been inserted yet because the library disables the foreign key checks before inserting the fixtures into the database.

JSON

[
  {
    "name": "Owen Sound",
    "region": "ON",
    "country": "Sierra Leone"
  }
]

CSV

The delimiter is detected automatically.

name;region;country
Owen Sound;ON;Sierra Leone

YAML

- name: Owen Sound
  region: ON
  country: Sierra Leone

PHP

<?php

return [
    [
        'name' => 'Owen Sound',
        'region' => 'ON',
        'country' => 'Sierra Leone'
    ]
];

mayconbordin/l5-fixtures 适用场景与选型建议

mayconbordin/l5-fixtures 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 123.51k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「yaml」 「json」 「fixtures」 「csv」 「laravel」 「laravel 5」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mayconbordin/l5-fixtures 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mayconbordin/l5-fixtures 我们能提供哪些服务?
定制开发 / 二次开发

基于 mayconbordin/l5-fixtures 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-07