承接 kerigard/laravel-data 相关项目开发

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

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

kerigard/laravel-data

最新稳定版本:v1.0.2

Composer 安装命令:

composer require kerigard/laravel-data

包简介

Fill the database with required data

关键字:

README 文档

README

Build Status Total Downloads Latest Stable Version License

This package adds an alternative way to populate the database regarding migrations and seeders.

Installation

Install package via composer:

composer require kerigard/laravel-data

Usage

Implement the MustFillData interface into the model and set the required data.

use Illuminate\Database\Eloquent\Model;
use Kerigard\LaravelData\Contracts\MustFillData;
use Kerigard\LaravelData\Data;

class Role extends Model implements MustFillData
{
    public function data(): Data
    {
        return Data::make([
            ['id' => 1, 'name' => 'Admin'],
            ['id' => 2, 'name' => 'User'],
        ]);
    }
}

Run artisan command.

php artisan db:data

As a result of executing the command, all unnecessary data will be deleted from the table and new ones will be inserted if they do not already exist.

You can also disable deleting existing data from the table.

public function data(): Data
{
    return Data::make([
        // ...
    ], false);
}

Use the withoutEvents method to disable all model events while a command is running. As a parameter, you can pass a list of events that should not be ignored.

class MyModel extends Model implements MustFillData
{
    public static function booted()
    {
        static::creating(function (MyModel $model) {
            $model->slug = Str::slug($model->name);
        });
    }

    public function data(): Data
    {
        return Data::make([
            // ...
        ])->withoutEvents(['eloquent.creating: '.MyModel::class]);
    }
}

If the model is present in the vendor package or does not exist, fill in the data in the AppServiceProvider.

use Kerigard\LaravelData\Data;
use Kerigard\LaravelData\DataManager;

public function boot()
{
    DataManager::model(VendorModel::class, fn () => Data::make([
        // ...
    ]));

    DataManager::table('role_user', fn () => Data::make([
        // ...
    ]));

    DataManager::table([
        'connection' => 'db2',
        'table' => 'permissions',
        'primaryKey' => 'id',
        'timestamps' => true,
    ], fn () => Data::make([
        // ...
    ]));
}

Changelog

Please see the CHANGELOG for more information on what has changed recently.

License

MIT. Please see the LICENSE FILE for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固