- Notifications
You must be signed in to change notification settings - Fork0
A Laravel library to effortlessly generate Dart/Flutter models directly from Laravel migrations or database schema via the command line.
License
MHasanKN/laravel-dart-models
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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.
- Generate models from Laravelmigrations.
- Generate models from yourdatabase schema.
- Supports nullable fields and various Laravel column types.
- Provides JSON serialization methods for Dart models.
- 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,],Generate models from migrations:bashCopy codephp artisan dart:models --from-migrationsThis 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:bashCopy codephp artisan dart:models --from-databaseThis command connects to your Laravel database and generates Dart models based on the existing table schema.
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!
Feel free to open issues or submit PRs. Contributions are welcome!
This package is licensed under the MIT License. SeeLICENSE.md for details.
About
A Laravel library to effortlessly generate Dart/Flutter models directly from Laravel migrations or database schema via the command line.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.