Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mhasankn/laravel-dart-models
A Laravel library to effortlessly generate Dart/Flutter models directly from Laravel migrations or database schema via the command line.
https://github.com/mhasankn/laravel-dart-models
cli-tools dart database-models flutter laravel laravel-migrations laravel-package migration migration-tools models-generation php
Last synced: 27 days ago
JSON representation
A Laravel library to effortlessly generate Dart/Flutter models directly from Laravel migrations or database schema via the command line.
- Host: GitHub
- URL: https://github.com/mhasankn/laravel-dart-models
- Owner: MHasanKN
- License: mit
- Created: 2024-10-24T13:27:35.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-10-24T13:57:33.000Z (3 months ago)
- Last Synced: 2024-10-25T09:58:46.705Z (3 months ago)
- Topics: cli-tools, dart, database-models, flutter, laravel, laravel-migrations, laravel-package, migration, migration-tools, models-generation, php
- Language: PHP
- Homepage:
- Size: 4.31 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Dart Models
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
1. Add this package to your Laravel project via Composer:```bash
composer require mhasankn/dart-models
```2. 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
1. 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.2. 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 json) => User(
name: json['name'] as String,
email: json['email'] as String,
createdAt: json['createdAt'] != null
? DateTime.parse(json['createdAt'])
: null,
);Map 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](LICENSE.md) for details.