cli/templates/skills/backend-laravel/SKILL.md
Laravel PHP backend development conventions. Use when working on Laravel/PHP projects.
npx skillsauth add binhtranquoc/agent-kit-skill backend-laravelInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill provides specific conventions for Laravel backend development.
project-standards skillComplex Business Logic MUST be separated into Service Classes.
app/Services/{Name}Service.php<?php
declare(strict_types=1);
namespace App\Services;
class UserService
{
public function __construct(
private readonly UserRepository $userRepository,
) {}
public function createUser(array $data): User
{
// Business logic here
return $this->userRepository->create($data);
}
}
Use when strict separation of DB query logic is needed.
app/Repositories/{Name}Repository.phpMUST use FormRequest to validate input.
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CreateUserRequest extends FormRequest
{
public function rules(): array
{
return [
'email' => ['required', 'email', 'unique:users'],
'password' => ['required', 'min:8'],
];
}
}
<?php
declare(strict_types=1);
UserController (Singular)User (Singular)users (Plural)$camelCasecreate_users_tableControllers should be thin - delegate to Services.
<?php
namespace App\Http\Controllers;
use App\Http\Requests\CreateUserRequest;
use App\Services\UserService;
class UserController extends Controller
{
public function __construct(
private readonly UserService $userService,
) {}
public function store(CreateUserRequest $request)
{
$user = $this->userService->createUser($request->validated());
return response()->json([
'success' => true,
'data' => new UserResource($user),
], 201);
}
}
Prioritize using Eloquent Relationships instead of manual Query Builder.
// Good
$user->orders()->where('status', 'pending')->get();
// Avoid
DB::table('orders')->where('user_id', $user->id)->where('status', 'pending')->get();
ALWAYS Eager Load with with().
// Bad - N+1 problem
$users = User::all();
foreach ($users as $user) {
echo $user->profile->name; // N additional queries
}
// Good - Eager loading
$users = User::with('profile')->get();
Use API Resource to transform data returned as JSON.
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => $this->id,
'email' => $this->email,
'created_at' => $this->created_at->toIso8601String(),
];
}
}
public function test_user_can_be_created(): void
{
$response = $this->postJson('/api/users', [
'email' => '[email protected]',
'password' => 'password123',
]);
$response->assertStatus(201)
->assertJsonStructure(['success', 'data' => ['id', 'email']]);
}
development
Activate Code Reviewer mode for code review and quality assurance. Use when reviewing code for bugs, security issues, or optimization opportunities.
development
Default Implementer mode for writing production code. Use for general coding tasks following project conventions.
development
Activate Debugger mode for systematic bug fixing. Use when debugging errors, investigating issues, or fixing bugs.
testing
Activate Architect mode for system design and architecture decisions. Use when planning features, designing systems, or making architectural choices.