mhasankn/dart-models
Composer 安装命令:
composer require mhasankn/dart-models
包简介
Laravel library to easily generate models for Dart/Flutter from command line.
README 文档
README
This package allows you to generate Dart/Flutter models directly from Laravel migrations or database schema. It simplifies the creation of strongly-typed Dart models by parsing your Laravel structure and generating code accordingly.
Features
- Generate models from Laravel migrations.
- Generate models from your database schema.
- Supports nullable fields and various Laravel column types.
- Provides JSON serialization methods for Dart models.
Installation
- Add this package to your Laravel project via Composer:
composer require mhasankn/dart-models
- In your Laravel project, open config/app.php or bootstrap/providers.php and add the following entry to the providers array:
'providers' => [
// Other service providers...
Mhasankn\DartModels\DartModelsServiceProvider::class,
],
Usage
-
Generate models from migrations: bash Copy code php artisan dart:models --from-migrations This command will parse all migration files in your Laravel project and generate Dart models based on the table structure.
-
Generate models from the database schema: bash Copy code php artisan dart:models --from-database This command connects to your Laravel database and generates Dart models based on the existing table schema.
Example Dart Model
Below is an example of a Dart model generated by the package:
class User {
final String name;
final String email;
final DateTime? createdAt;
User({required this.name, required this.email, this.createdAt});
factory User.fromJson(Map<String, dynamic> json) => User(
name: json['name'] as String,
email: json['email'] as String,
createdAt: json['createdAt'] != null
? DateTime.parse(json['createdAt'])
: null,
);
Map<String, dynamic> toJson() => {
'name': name,
'email': email,
'createdAt': createdAt?.toIso8601String(),
};
}
This formatting ensures clarity and consistency for the users of your package. Let me know if further adjustments are needed!
Contributing
Feel free to open issues or submit PRs. Contributions are welcome!
License
This package is licensed under the MIT License. See LICENSE.md for details.
mhasankn/dart-models 适用场景与选型建议
mhasankn/dart-models 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 135 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mhasankn/dart-models 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mhasankn/dart-models 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 135
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-24