定制 rymanalu/factory-generator 二次开发

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

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

rymanalu/factory-generator

Composer 安装命令:

composer require rymanalu/factory-generator

包简介

Laravel 5 Model Factory Generator.

README 文档

README

This package offers a lazy way to create a new model factory files, since Laravel (< 5.5) have no Artisan command to generate it.

Installation

First, install this package via the Composer package manager:

composer require rymanalu/factory-generator

Next, you should add the FactoryGeneratorServiceProvider to the providers array of your config/app.php configuration file:

Rymanalu\FactoryGenerator\FactoryGeneratorServiceProvider::class,

Now, you should be able to generate a new model factory file by executing php artisan make:factory command.

Usage

php artisan make:factory accept one argument: the model class name with the namespace. Make sure the model is already exists before executing this command.

Example:

php artisan make:factory "App\Post"

The command will generate a file named PostFactory.php in /path/to/your-laravel-project/database/factories directory:

<?php

use App\Post;
use Faker\Generator as Faker;

$factory->define(Post::class, function (Faker $faker) {
    //
});

This command also using the fillable array of the model and pair all of fillable values to $faker->word as default (you can change it to the proper Faker Formatters or other value later) in the generated model factory.

For example, if the App\Post has fillable array like this:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'text',
    ];
}

Then, the command will generate the PostFactory.php like this:

<?php

use App\Post;
use Faker\Generator as Faker;

$factory->define(Post::class, function (Faker $faker) {
    return [
        'text' => $faker->word,
    ];
});

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固