api-controller

Create a new Laravel API controller following this project's patterns. Use when creating new API endpoints, CRUD controllers, or backoffice controllers.

16 stars

Best use case

api-controller is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Create a new Laravel API controller following this project's patterns. Use when creating new API endpoints, CRUD controllers, or backoffice controllers.

Teams using api-controller should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/api-controller/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/backend/api-controller/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/api-controller/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How api-controller Compares

Feature / Agentapi-controllerStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Create a new Laravel API controller following this project's patterns. Use when creating new API endpoints, CRUD controllers, or backoffice controllers.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Create API Controller

Create a new Laravel API controller for `$ARGUMENTS` following this project's established patterns.

## Project Patterns

### Controller Location
- Public API controllers: `app/Http/Controllers/`
- Auth controllers: `app/Http/Controllers/Auth/`

### Standard Controller Structure
```php
<?php

namespace App\Http\Controllers;

use App\Models\{ModelName};
use App\Http\Resources\{ModelName}Resource;
use App\Http\Resources\{ModelName}Collection;
use App\Http\Requests\{ModelName}StoreRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class {ModelName}Controller extends Controller
{
    // GET /api/{resource} - List all
    public function index()
    {
        return new {ModelName}Collection({ModelName}::all());
    }

    // GET /api/{resource}/{id} - Show one
    public function show($id)
    {
        return new {ModelName}Resource({ModelName}::findOrFail($id));
    }

    // POST /api/{resource} - Create
    public function store({ModelName}StoreRequest $request)
    {
        $model = {ModelName}::create($request->validated());

        // Invalidate cache if using caching
        Cache::forget('{resource}-all');

        return new {ModelName}Resource($model);
    }

    // PUT /api/{resource}/{id} - Update
    public function update(Request $request, $id)
    {
        $model = {ModelName}::findOrFail($id);
        $model->update($request->all());

        Cache::forget('{resource}-all');

        return new {ModelName}Resource($model);
    }

    // DELETE /api/{resource}/{id} - Delete
    public function destroy($id)
    {
        {ModelName}::destroy($id);
        Cache::forget('{resource}-all');

        return response()->json(['success' => true]);
    }
}
```

### Caching Pattern (used in InventoryController, CategoryController)
```php
public function all()
{
    return Cache::remember('inventory-all', 60, function() {
        return new InventoryCollection(Inventory::all());
    });
}
```

### Filtering Pattern (used in InvoiceController, SalesController)
```php
use App\Models\Traits\Revenue; // or SalesRevenue, InventoryFilters

public function index(Request $request)
{
    return Invoice::filter($request)->paginate(15);
}
```

### Pusher Broadcasting (for real-time updates)
```php
use Services\Pusher;

// After mutations that need real-time sync:
try {
    Pusher::trigger('tables-update', []);
} catch (\Exception $e) {
    \Log::error($e->getMessage());
}
```

### Backoffice Controller Pattern
Backoffice routes are prefixed with `/api/backoffice/` and may have different methods:
- `allBackoffice()` - Admin-specific listing with more details
- `export()` - Excel/CSV export functionality

## Steps

1. Create the controller in `app/Http/Controllers/`
2. Create corresponding Resource class in `app/Http/Resources/`
3. Create Collection class if needed
4. Create FormRequest for validation in `app/Http/Requests/`
5. Add routes to `routes/api.php`
6. Consider if caching is needed for read operations
7. Add Pusher triggers if real-time updates are needed

## Route Registration Pattern
```php
// In routes/api.php

// Public routes
Route::get('{resources}', [{ModelName}Controller::class, 'index']);
Route::get('{resource}/{id}', [{ModelName}Controller::class, 'show']);
Route::post('{resources}', [{ModelName}Controller::class, 'store']);

// Backoffice routes (in the backoffice prefix group)
Route::prefix('/backoffice')->group(function () {
    Route::put('/{resources}/{id}', [{ModelName}Controller::class, 'update']);
    Route::delete('/{resources}/{id}', [{ModelName}Controller::class, 'destroy']);
});
```

Related Skills

restcontroller-conventions

16
from diegosouzapw/awesome-omni-skill

Specifies standards for RestController classes, including API route mappings, HTTP method annotations, dependency injection, and error handling with ApiResponse and GlobalExceptionHandler.

bgo

10
from diegosouzapw/awesome-omni-skill

Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.

Coding & Development

moai-lang-r

16
from diegosouzapw/awesome-omni-skill

R 4.4+ best practices with testthat 3.2, lintr 3.2, and data analysis patterns.

moai-lang-python

16
from diegosouzapw/awesome-omni-skill

Python 3.13+ development specialist covering FastAPI, Django, async patterns, data science, testing with pytest, and modern Python features. Use when developing Python APIs, web applications, data pipelines, or writing tests.

moai-icons-vector

16
from diegosouzapw/awesome-omni-skill

Vector icon libraries ecosystem guide covering 10+ major libraries with 200K+ icons, including React Icons (35K+), Lucide (1000+), Tabler Icons (5900+), Iconify (200K+), Heroicons, Phosphor, and Radix Icons with implementation patterns, decision trees, and best practices.

moai-foundation-trust

16
from diegosouzapw/awesome-omni-skill

Complete TRUST 4 principles guide covering Test First, Readable, Unified, Secured. Validation methods, enterprise quality gates, metrics, and November 2025 standards. Enterprise v4.0 with 50+ software quality standards references.

moai-foundation-memory

16
from diegosouzapw/awesome-omni-skill

Persistent memory across sessions using MCP Memory Server for user preferences, project context, and learned patterns

moai-foundation-core

16
from diegosouzapw/awesome-omni-skill

MoAI-ADK's foundational principles - TRUST 5, SPEC-First TDD, delegation patterns, token optimization, progressive disclosure, modular architecture, agent catalog, command reference, and execution rules for building AI-powered development workflows

moai-cc-claude-md

16
from diegosouzapw/awesome-omni-skill

Authoring CLAUDE.md Project Instructions. Design project-specific AI guidance, document workflows, define architecture patterns. Use when creating CLAUDE.md files for projects, documenting team standards, or establishing AI collaboration guidelines.

moai-alfred-language-detection

16
from diegosouzapw/awesome-omni-skill

Auto-detects project language and framework from package.json, pyproject.toml, etc.

mnemonic

16
from diegosouzapw/awesome-omni-skill

Unified memory system - aggregates communications and AI sessions across all channels into searchable, analyzable memory

mlops

16
from diegosouzapw/awesome-omni-skill

MLflow, model versioning, experiment tracking, model registry, and production ML systems