The Artisan-like CLI for Magic. Scaffold controllers, models, views, migrations, and more with a single command.
dart pub global activate fluttersdk_magic_cliEnsure ~/.pub-cache/bin is in your PATH.
# Navigate to your Flutter project
cd my_app
# Initialize Magic with all features
magic init
# Or exclude specific features
magic init --without-database --without-events| Command | Description |
|---|---|
magic init |
Initialize Magic in an existing Flutter project |
magic key:generate |
Generate a new application encryption key |
| Command | Description |
|---|---|
magic make:model User |
Create an Eloquent model |
magic make:controller User |
Create a controller |
magic make:view Login |
Create a view class |
magic make:policy Post |
Create an authorization policy |
magic make:migration create_users_table |
Create a database migration |
magic make:seeder UserSeeder |
Create a database seeder |
magic make:factory UserFactory |
Create a model factory |
magic make:lang tr |
Create a language file |
Initializes Magic in your Flutter project with the recommended directory structure and configuration.
magic initOptions:
| Option | Description |
|---|---|
--without-database |
Skip database support |
--without-cache |
Skip caching |
--without-auth |
Skip authentication |
--without-events |
Skip event system |
--without-localization |
Skip localization/i18n |
Creates an Eloquent-style model with optional related files.
magic make:model User
magic make:model Post --migration --controller --factory
magic make:model Comment -mcf # ShorthandOptions:
| Option | Short | Description |
|---|---|---|
--migration |
-m |
Create a migration file |
--controller |
-c |
Create a controller |
--factory |
-f |
Create a model factory |
--seeder |
-s |
Create a seeder |
--all |
-a |
Create all related files |
Output:
lib/app/models/user.dart
Creates a controller class.
magic make:controller UserController
magic make:controller User # Auto-appends 'Controller'
magic make:controller Admin/Dashboard # Nested pathOptions:
| Option | Description |
|---|---|
--resource, -r |
Create a resource controller with CRUD methods |
--model, -m |
Specify the model for resource controller |
Output:
lib/app/controllers/user_controller.dart
Creates a view class with MagicStateMixin.
magic make:view LoginView
magic make:view Login # Auto-appends 'View'
magic make:view Auth/Register # Nested pathOutput:
lib/resources/views/login_view.dart
Creates a database migration file.
magic make:migration create_users_table
magic make:migration add_email_to_users_tableOptions:
| Option | Description |
|---|---|
--create, -c |
The table to be created |
--table, -t |
The table to migrate |
Output:
lib/database/migrations/2024_01_15_120000_create_users_table.dart
Creates an authorization policy.
magic make:policy PostPolicy
magic make:policy Post # Auto-appends 'Policy'
magic make:policy Comment --model=CommentOptions:
| Option | Description |
|---|---|
--model, -m |
The model that the policy applies to |
Output:
lib/app/policies/post_policy.dart
Creates a database seeder.
magic make:seeder UserSeederOutput:
lib/database/seeders/user_seeder.dart
Creates a model factory.
magic make:factory UserFactory
magic make:factory User # Auto-appends 'Factory'Output:
lib/database/factories/user_factory.dart
Creates a language JSON file.
magic make:lang tr
magic make:lang esOutput:
assets/lang/tr.json
Generates a random encryption key for your application.
magic key:generateUpdates your .env file with:
APP_KEY=base64:randomGeneratedKey...
After running magic init, your project will have:
lib/
├── config/
│ ├── app.dart
│ ├── auth.dart
│ └── database.dart
├── app/
│ ├── controllers/
│ ├── models/
│ └── policies/
├── database/
│ ├── migrations/
│ ├── seeders/
│ └── factories/
├── resources/
│ └── views/
├── routes/
│ └── web.dart
└── main.dart
Contributions are welcome! Please read our contributing guidelines.
Magic CLI is open-sourced software licensed under the MIT license.