api-controller
FreeNo executable scriptsNot checkedCreate a new Laravel API controller following this project's patterns. Use when creating new API endpoints, CRUD controllers, or backoffice controllers.
by diegosouzapw★ 68 GitHub starsAbout this skill
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
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)
public function all()
{
return Cache::remember('inventory-all', 60, function() {
return new InventoryCollection(Inventory::all());
});
}
Filtering Pattern (used in InvoiceController, SalesController)
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)
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 detailsexport()- Excel/CSV export functionality
Steps
- Create the controller in
app/Http/Controllers/ - Create corresponding Resource class in
app/Http/Resources/ - Create Collection class if needed
- Create FormRequest for validation in
app/Http/Requests/ - Add routes to
routes/api.php - Consider if caching is needed for read operations
- Add Pusher triggers if real-time updates are needed
Route Registration Pattern
// 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']);
});
Install api-controller in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the api-controller skill do?
Create a new Laravel API controller following this project's patterns. Use when creating new API endpoints, CRUD controllers, or backoffice controllers.
How do I install the api-controller skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the api-controller skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
by Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
by Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
by Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
by Anthropic