PHPackages                             marghoobsuleman/apiwizard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. marghoobsuleman/apiwizard

ActiveLibrary[API Development](/categories/api)

marghoobsuleman/apiwizard
=========================

Generate Laravel models, relations, and APIs from an interactive command line

v1.0.1(5mo ago)02MITPHPPHP ^8.2CI passing

Since Oct 13Pushed 5mo agoCompare

[ Source](https://github.com/marghoobsuleman/apiwizard)[ Packagist](https://packagist.org/packages/marghoobsuleman/apiwizard)[ RSS](/packages/marghoobsuleman-apiwizard/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (4)Used By (0)

APIWizard - Laravel API Generator
=================================

[](#apiwizard---laravel-api-generator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6829081e5237fb97f60e1da1e5b9818581cecdbd26abb3408cd47db0a9d6d7db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617267686f6f6273756c656d616e2f61706977697a6172642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/marghoobsuleman/apiwizard)[![Total Downloads](https://camo.githubusercontent.com/8aa562244b40c52ffc18fd6d159b861a4b1d7d25312acb2fc2c3f9d4dedf8ca2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617267686f6f6273756c656d616e2f61706977697a6172642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/marghoobsuleman/apiwizard)

A powerful Laravel package that generates models, relations, and complete REST APIs from an interactive command line interface or via command options.

✨ Features
----------

[](#-features)

- 🎯 **Interactive CLI** - User-friendly prompts guide you through the generation process
- 🚀 **Quick Generation** - Create models, controllers, and routes in seconds
- 🔗 **Automatic Relations** - Define and generate model relationships effortlessly
- 🔄 **Safe Updates** - Add relations to existing models without overwriting code
- 🎨 **Data Transformation** - Optional transform methods for customizing API responses
- 📦 **Complete REST API** - Generates full CRUD endpoints automatically
- ⚙️ **Non-Interactive Mode** - Use command options for automation and scripting
- 🛠️ **Customizable** - Publish and modify stubs to match your coding style
- 📝 **PSR-4 Compliant** - Follows Laravel and PHP best practices

📋 Requirements
--------------

[](#-requirements)

- PHP 8.2 or higher
- Laravel 11.x or 12.x

📦 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require marghoobsuleman/apiwizard
```

The package will automatically register its service provider.

### Publish Configuration (Optional)

[](#publish-configuration-optional)

```
php artisan vendor:publish --tag=apiwizard-config
```

### Publish Stubs (Optional)

[](#publish-stubs-optional)

```
php artisan vendor:publish --tag=apiwizard-stubs
```

🚀 Usage
-------

[](#-usage)

### Available Commands

[](#available-commands)

The package provides two commands (both work identically):

```
php artisan apiwizard:generate
# OR
php artisan modelwizard:generate
```

### Interactive Mode

[](#interactive-mode)

Run the command and follow the prompts:

```
php artisan apiwizard:generate
```

#### Example Interactive Session:

[](#example-interactive-session)

```
🧙 APIWizard - Laravel API Generator

Enter table name: users
Model name will be: User

Does it have any relations? (yes/no): yes
Enter related table name: posts
Type of relation:
  [0] hasOne
  [1] hasMany
  [2] belongsTo
  [3] belongsToMany
 > 1

✓ Added hasMany relation with posts

Add another relation? (yes/no): no

Do you want to modify returned data (add transform method)? (yes/no): yes

Do you want to create an API endpoint? (yes/no): yes
Enter API endpoint [/api/users]: /api/users

🔨 Generating files...

✓ Model created: /app/Models/User.php
✓ Related model created: /app/Models/Post.php
✓ Controller created: /app/Http/Controllers/API/UserController.php
✓ Routes added to: routes/api.php

✅ Generation completed successfully!

```

### Non-Interactive Mode

[](#non-interactive-mode)

Use command options for automation:

```
php artisan apiwizard:generate --table=users --relations=posts:hasMany --endpoint=/api/users --transform
```

#### Available Options:

[](#available-options)

OptionDescriptionExample`--table`Table name (required for non-interactive)`--table=users``--relations`Relations in format "table:type" (can be used multiple times)`--relations=posts:hasMany --relations=profile:hasOne``--endpoint`API endpoint path`--endpoint=/api/users``--transform`Include transform method in model`--transform``--no-api`Skip API generation (model only)`--no-api`#### Examples:

[](#examples)

**Generate model with multiple relations:**

```
php artisan apiwizard:generate \
  --table=users \
  --relations=posts:hasMany \
  --relations=profile:hasOne \
  --relations=roles:belongsToMany \
  --endpoint=/api/users \
  --transform
```

**Generate model without API:**

```
php artisan apiwizard:generate --table=products --no-api
```

**Simple model with API:**

```
php artisan apiwizard:generate --table=categories --endpoint=/api/categories
```

📚 What Gets Generated
---------------------

[](#-what-gets-generated)

### 1. Model File

[](#1-model-file)

Generated at `app/Models/{ModelName}.php`:

```
