PHPackages                             iamgerwin/laravel-api-scaffold - 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. iamgerwin/laravel-api-scaffold

ActiveLibrary[API Development](/categories/api)

iamgerwin/laravel-api-scaffold
==============================

A Laravel package to scaffold Service layer architecture with API resources, controllers, and tests

0.3.6(7mo ago)013[1 issues](https://github.com/iamgerwin/laravel-api-scaffold/issues)MITPHPPHP ^8.1|^8.2|^8.3|^8.4CI passing

Since Oct 7Pushed 7mo agoCompare

[ Source](https://github.com/iamgerwin/laravel-api-scaffold)[ Packagist](https://packagist.org/packages/iamgerwin/laravel-api-scaffold)[ Docs](https://github.com/iamgerwin/laravel-api-scaffold)[ RSS](/packages/iamgerwin-laravel-api-scaffold/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (19)Used By (0)

Laravel API Scaffold
====================

[](#laravel-api-scaffold)

A comprehensive Laravel package that scaffolds Service layer architecture with API resources, controllers, and tests. This package follows best practices and provides a battle-tested structure for building maintainable Laravel applications.

Description
-----------

[](#description)

Laravel API Scaffold automates the creation of service-oriented architecture components in your Laravel application. It generates well-structured service classes with interfaces, controllers with dependency injection, form requests, API resources, and comprehensive tests, all following Laravel conventions and best practices.

Features
--------

[](#features)

- 🏗️ **Service Layer Architecture**: Automatically generates service classes with their interfaces
- 🔌 **Dependency Injection**: Auto-registers service bindings in AppServiceProvider
- 🎯 **Complete API Scaffolding**: Creates Models, Migrations, Controllers, Requests, and Resources
- 🚀 **Laravel 11+ API Setup**: Automatically runs `php artisan install:api` for Laravel 11+ projects
- 🛣️ **Interactive Route Management**: Choose to append routes to api.php or create separate route files
- 🎛️ **Admin Panel Integration**: Generate Laravel Nova or Filament resources with auto-detection
- 📝 **Entity Documentation**: Auto-generate comprehensive markdown documentation for each entity
- 🧪 **Testing Ready**: Generates Pest/PHPUnit test files with common test cases
- ⚙️ **Highly Configurable**: Customize paths, namespaces, and generation options
- 🔒 **Safe Operations**: Automatic backups of existing files before modifications
- 📦 **Modular Approach**: Generate only what you need with granular options
- 🎨 **Custom Stubs**: Publish and customize stub templates to match your coding style

Requirements
------------

[](#requirements)

- PHP 8.1, 8.2, 8.3, or 8.4
- Laravel 10.x, 11.x, or 12.x
- Composer

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require iamgerwin/laravel-api-scaffold
```

### Publish Configuration (Optional)

[](#publish-configuration-optional)

Publish the configuration file to customize the package behavior:

```
php artisan vendor:publish --tag="api-scaffold-config"
```

### Publish Stubs (Optional)

[](#publish-stubs-optional)

Publish the stub templates if you want to customize the generated files:

```
php artisan vendor:publish --tag="api-scaffold-stubs"
```

Usage
-----

[](#usage)

### Interactive Mode (New!)

[](#interactive-mode-new)

The package now features an intuitive interactive mode that guides you through the scaffolding process. When you run the command without any flags, it automatically launches an interactive wizard:

```
php artisan make:service-api Product
```

The interactive wizard will:

1. **Preset Selection**: Choose from predefined templates (Minimal, API Complete, Service Layer, or Custom)
2. **Component Selection**: Select which components to generate
3. **Preview &amp; Confirm**: Review your selections before generating files
4. **Cache Preferences**: Remember your choices for next time

#### Available Presets

[](#available-presets)

- **Minimal**: Service and Interface only
- **API Complete**: Full API scaffold with all components (Service, Interface, Model, Migration, Controller, Request, Resource, Tests)
- **Service Layer**: Service, Interface, Model, and Tests (great for business logic-heavy applications)
- **Custom**: Choose components individually

#### Interactive Mode Options

[](#interactive-mode-options)

```
# Force interactive mode (even with flags)
php artisan make:service-api Product --interactive

# Disable interactive mode (use flags instead)
php artisan make:service-api Product --no-interactive --all
```

### Automatic Laravel 11+ API Setup

[](#automatic-laravel-11-api-setup)

When using Laravel 11 or higher, the package automatically detects if your project needs API scaffolding:

- **Auto-detection**: Checks if `routes/api.php` exists
- **Auto-installation**: Runs `php artisan install:api` if needed
- **Seamless setup**: Installs Laravel Sanctum and sets up API routes automatically

This ensures your Laravel 11+ project is properly configured for API development without manual intervention.

### Interactive Route Management

[](#interactive-route-management)

After generating a controller, the package offers an interactive prompt to add routes for your new resource:

```
Would you like to add API routes for this resource? (yes/no)
```

You can choose between two route management strategies:

#### Option 1: Append to routes/api.php

[](#option-1-append-to-routesapiphp)

Routes are added directly to your main API routes file:

```
// Product API Routes
Route::apiResource('products', ProductController::class);
```

**Best for:**

- Small to medium projects
- Quick prototyping
- Simple API structures

#### Option 2: Create separate route file

[](#option-2-create-separate-route-file)

Creates a dedicated route file at `routes/api/{model}.php`:

```
