glamorous/laravel-data-loader
Composer 安装命令:
composer require glamorous/laravel-data-loader
包简介
Small package to provide tools for data migrations and loading initial data into your database
README 文档
README
Small package to provide tools for data migrations and loading initial data into your database.
Installation
You can install the package via composer:
composer require glamorous/laravel-data-loader
You should publish the config file with:
php artisan vendor:publish --tag="laravel-data-loader-config"
This is the contents of the published config file:
return [ 'loaders' => [ // EnsureSomeDataIsPresent::class, ], ];
Usage
Provide a list of loaders in config/data-loader.php with their class names. Those classes should implement the DataLoader-interface.
Example data loader class
<?php namespace Database\States; use App\Models\User; use Glamorous\DataLoader\Database\DataLoader; readonly final class EnsureSuperAdminIsPresent implements DataLoader { public function __invoke(): void { $user = User::query() ->where('identifier', '=', $this->getSuperAdminIdentifier()) ->firstOrNew(); $user->identifier = $this->getSuperAdminIdentifier(); $user->email = $this->getEmail(); $user->password = $this->getPassword(); $user->name = 'Super Admin'; $user->save(); } public function shouldLoad(): bool { return !User::where('identifier', '=', $this->getSuperAdminIdentifier())->exists(); } protected function getEmail(): string { return config('custom.superadmin.email'); } protected function getPassword(): string { return Hash::make(config('custom.superadmin.password')) } protected function getSuperAdminIdentifier(): string { return config('custom.superadmin.identifier'); } }
Calling the loader
The command can be run after the migrations if you put the following in the boot of a Service Provider:
Event::listen(MigrationsEnded::class, function() { Artisan::call(DataLoaderCommand::class); });
Or you can just call the command in your CI-scripts:
php artisan data-loader:run
It's also possible to run the data-loader only for one specific data-loader class:
php artisan data-loader:run EnsureSuperAdminIsPresent
Options
If necessary you can run the command with the --force flag. This way it would not check if its data needs to be loaded or not. It's required to confirm your choice.
If you want to see which loaders would be executed, without executing them, you can pass the --dry-run option, and it will show you the loaders that would have executed.
Contributing
Package is open for pull requests!
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
glamorous/laravel-data-loader 适用场景与选型建议
glamorous/laravel-data-loader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.14k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「laravel」 「data-loader」 「glamorous」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 glamorous/laravel-data-loader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 glamorous/laravel-data-loader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 glamorous/laravel-data-loader 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
PHP module for MySql database
Alfabank REST API integration
统计信息
- 总下载量: 2.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-08