一键导入
policies
Centralised authorization logic for a given Eloquent model. Policies define per-ability access control and are enforced at the controller level.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Centralised authorization logic for a given Eloquent model. Policies define per-ability access control and are enforced at the controller level.
用 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 | policies |
| description | Centralised authorization logic for a given Eloquent model. Policies define per-ability access control and are enforced at the controller level. |
| compatible_agents | ["architect","implement","refactor","review"] |
app/Policies/PascalCase with a Policy suffix, named after the model they protect: InvoicePolicy, PostPolicyviewAny, view, create, update, delete, restore, forceDeletecan:* is equivalent enforcement to calling $this->authorize() in controllersModelPolicy naming conventionAuthServiceProvidernamespace App\Policies;
use App\Models\Invoice;
use App\Models\User;
class InvoicePolicy
{
public function viewAny(User $user): bool
{
return $user->isAdmin();
}
public function view(User $user, Invoice $invoice): bool
{
return $user->id === $invoice->user_id || $user->isAdmin();
}
public function create(User $user): bool
{
return $user->hasVerifiedEmail();
}
public function update(User $user, Invoice $invoice): bool
{
return $user->id === $invoice->user_id && $invoice->isDraft();
}
public function delete(User $user, Invoice $invoice): bool
{
return $user->isAdmin();
}
}
// Usage in controller
public function update(UpdateInvoiceRequest $request, Invoice $invoice): InvoiceResource
{
$this->authorize('update', $invoice);
// ...
}
// Usage in Form Request
public function authorize(): bool
{
return $this->user()->can('update', $this->route('invoice'));
}
// Safe always-true example (explicitly public endpoint)
public function authorize(): bool
{
// Intentionally public route: no model-sensitive data is exposed.
return true;
}
// Usage via route middleware
Route::put('/invoices/{invoice}', [InvoiceController::class, 'update'])
->middleware('can:update,invoice');
return true in authorize() without documenting the intentControllers/SKILL.md — the layer where policies are enforcedFormRequests/SKILL.md — can use can() in authorize() method