Skip to content

Commit f482cfa

Browse files
committed
Initial commit for Laravel-Dart Models library
0 parents  commit f482cfa

File tree

5,149 files changed

+592577
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,149 files changed

+592577
-0
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [1.0.0] - 2024-10-24
6+
### Added
7+
- Initial release of Laravel Dart Models package.
8+
- Command to generate models from migrations (`php artisan dart:models --from-migrations`).
9+
- Command to generate models from database schema (`php artisan dart:models --from-database`).
10+
- Support for JSON serialization in generated Dart models.

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Hasan Niazi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Laravel Dart Models
2+
3+
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.
4+
5+
## Features
6+
- Generate models from Laravel **migrations**.
7+
- Generate models from your **database schema**.
8+
- Supports nullable fields and various Laravel column types.
9+
- Provides JSON serialization methods for Dart models.
10+
11+
## Installation
12+
Add this package to your Laravel project via Composer:
13+
14+
```bash
15+
composer require mhasankn/dart-models
16+
```
17+
18+
## Usage
19+
1. Generate models from migrations:
20+
bash
21+
Copy code
22+
php artisan dart:models --from-migrations
23+
This command will parse all migration files in your Laravel project and generate Dart models based on the table structure.
24+
25+
2. Generate models from the database schema:
26+
bash
27+
Copy code
28+
php artisan dart:models --from-database
29+
This command connects to your Laravel database and generates Dart models based on the existing table schema.
30+
31+
## Example Dart Model
32+
Below is an example of a Dart model generated by the package:
33+
34+
```
35+
class User {
36+
final String name;
37+
final String email;
38+
final DateTime? createdAt;
39+
40+
User({required this.name, required this.email, this.createdAt});
41+
42+
factory User.fromJson(Map<String, dynamic> json) => User(
43+
name: json['name'] as String,
44+
email: json['email'] as String,
45+
createdAt: json['createdAt'] != null
46+
? DateTime.parse(json['createdAt'])
47+
: null,
48+
);
49+
50+
Map<String, dynamic> toJson() => {
51+
'name': name,
52+
'email': email,
53+
'createdAt': createdAt?.toIso8601String(),
54+
};
55+
}
56+
```
57+
58+
This formatting ensures clarity and consistency for the users of your package. Let me know if further adjustments are needed!
59+
60+
## Contributing
61+
Feel free to open issues or submit PRs. Contributions are welcome!
62+
63+
## License
64+
This package is licensed under the MIT License. See [LICENSE.md](LICENSE.md) for details.
65+

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "mhasankn/dart-models",
3+
"description": "Laravel library to easily generate models for Dart/Flutter from command line.",
4+
"type": "library",
5+
"require": {
6+
"laravel/framework": "^8.0 || ^9.0 || ^10.0 || ^11.0"
7+
},
8+
"license": "MIT License",
9+
"autoload": {
10+
"psr-4": {
11+
"Mhasankn\\DartModels\\": "src/"
12+
}
13+
},
14+
"authors": [
15+
{
16+
"name": "Hasan Niazi",
17+
"email": "106889523+MHasanKN@users.noreply.github.com"
18+
}
19+
]
20+
}

0 commit comments

Comments
 (0)