一键导入
helpers
Stateless utility classes providing shared formatting, conversion, or calculation logic needed across multiple parts of the application.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Stateless utility classes providing shared formatting, conversion, or calculation logic needed across multiple parts of the application.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Readonly data containers with typed factory methods (`fromArray`, `fromModel`, `fromCollection`, `fromRequest`) used to pass structured data between application layers — especially for external API responses, Eloquent models, and service boundaries. Use this skill whenever creating, reviewing, or refactoring DTOs, Data Transfer Objects, value objects for inter-layer communication, or mapping payloads from APIs, models, or collections into typed PHP objects. Also trigger when the user mentions spatie/laravel-data alternatives, data mapping, or payload normalization in a Laravel context.
Eloquent model conventions for mass assignment, casts, relationship naming, activity logging, and mandatory model tests (CRUD + relations).
Single-purpose business logic classes that encapsulate one well-defined business operation. Actions are the primary location for business logic in Laravel applications, invoked from controllers, commands, or jobs.
Albatros accounting API integration via Saloon. Use when working with app/Services/Albatros/, AlbatrosConnector, or Albatros DTOs.
Laravel Blade template conventions covering components, output escaping, security, structure, and formatting.
Artisan console command classes that serve as the CLI entry point for operations. Commands validate input and delegate all business logic to Actions or Services.
| name | helpers |
| description | Stateless utility classes providing shared formatting, conversion, or calculation logic needed across multiple parts of the application. |
| compatible_agents | ["architect","implement","refactor","review"] |
nesbot/carbon for date parsing).app/Helpers/*Helper.php.null, invalid format, boundary values).app/Helpers/PascalCase with a Helper suffix → StringHelper, MoneyHelper, DateHelperApp\Helpers\Formatting\, App\Helpers\Conversion\)static when output depends only on input arguments.namespace App\Helpers;
use Carbon\Carbon;
class DateHelper
{
public static function format(mixed $date, string $format = 'd M Y'): ?string
{
if (is_null($date)) {
return null;
}
return Carbon::parse($date)->format($format);
}
}
namespace App\Helpers;
class MoneyHelper
{
public static function format(int $amountInCents, string $currency = 'CHF'): string
{
return number_format($amountInCents / 100, 2) . ' ' . $currency;
}
}
// Usage in a Resource
'created_at' => DateHelper::format($this->created_at),
'amount' => MoneyHelper::format($this->amount_in_cents),
// Instance helper for injectable collaborators or config
namespace App\Helpers\Formatting;
class LocalizedMoneyFormatter
{
public function __construct(
private readonly string $defaultCurrency = 'CHF',
) {}
public function format(int $amountInCents, ?string $currency = null): string
{
$resolvedCurrency = $currency ?? $this->defaultCurrency;
return number_format($amountInCents / 100, 2) . ' ' . $resolvedCurrency;
}
}
use App\Helpers\DateHelper;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class DateHelperTest extends TestCase
{
#[Test]
public function it_formats_dates_and_handles_null(): void
{
$this->assertSame('21 Jan 2026', DateHelper::format('2026-01-21', 'd M Y'));
$this->assertNull(DateHelper::format(null));
}
}
AppHelper or Utils class — keep helpers domain-specificActions/SKILL.md — for business logicResources/SKILL.md — helpers are commonly used for formatting in API resources// BEFORE (anti-pattern): null silently becomes "now", masking missing data bugs
public static function format(?string $date, string $format = 'd M Y'): string
{
return Carbon::parse($date)->format($format);
}
// AFTER: explicit null contract preserves correctness at call sites
public static function format(?string $date, string $format = 'd M Y'): ?string
{
if ($date === null) {
return null;
}
return Carbon::parse($date)->format($format);
}