원클릭으로
laravel-actions
Actions are what the user does within an application. Use when working with actions.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Actions are what the user does within an application. Use when working with actions.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Write the documentation for an existing concept.
Write the documentation for an existing feature.
Build a complete API surface from an existing web controller. Use when the user asks to add API methods, expose a resource via API, or mirror a web controller as an API, especially for adminland resources. Activates when user mentions API methods, API controller, API routes, or wants to expose an existing web resource via API.
Write or update the public-facing marketing documentation page for API methods. Use when a new API controller is created, routes are added or changed, or when documentation pages are missing or out of sync with the codebase.
Write or update Bruno API documentation files for a given API controller. Use when a new API controller is created, routes are added or changed, or Bruno docs are missing or out of sync with the codebase.
Use when writing tests. Follow testing best practices, use Laravel's testing tools, and ensure tests are clear, maintainable, and cover relevant scenarios.
| name | laravel-actions |
| description | Actions are what the user does within an application. Use when working with actions. |
Actions should represent what a user wants to do, or what the system needs to do. The verb should try to follow when possible, the appropriate RESTful method names, like CreateXX, UpdateXX or DestroyXX.
// ✅ CORRECT
CreateJournal
DestroyUser
// ❌ INCORRECT
AccountCreated
<?php
declare(strict_types=1);
namespace App\Actions;
use App\Jobs\LogUserAction;
use App\Models\Member;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
/**
* Create an organization for a user.
* The user will be added to the organization as the first user.
*/
class CreateOrganization
{
private Organization $organization;
public function __construct(
public User $user,
public string $name,
) {}
public function execute(): Organization
{
$this->validate();
$this->create();
$this->generateSlug();
$this->addMembership();
$this->log();
return $this->organization;
}
private function validate(): void
{
// make sure the organization name doesn't contain any special characters
if (in_array(preg_match('/^[a-zA-Z0-9\s\-_]+$/', $this->name), [0, false], true)) {
throw ValidationException::withMessages([
'organization_name' => 'Organization name can only contain letters, numbers, spaces, hyphens and underscores',
]);
}
}
private function create(): void
{
$this->organization = Organization::query()->create([
'name' => $this->name,
]);
}
private function generateSlug(): void
{
$slug = $this->organization->id . '-' . Str::of($this->name)->slug('-');
$this->organization->slug = $slug;
$this->organization->save();
}
private function addMembership(): void
{
Member::query()->create([
'organization_id' => $this->organization->id,
'user_id' => $this->user->id,
'joined_at' => now(),
]);
}
private function log(): void
{
LogUserAction::dispatch(
organization: $this->organization,
user: $this->user,
action: 'organization_creation',
description: sprintf('Created an organization called %s', $this->name),
)->onQueue('low');
}
}
<?php
declare(strict_types=1);
namespace Tests\Unit\Actions;
use App\Actions\CreateOrganization;
use App\Jobs\LogUserAction;
use App\Models\Organization;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Illuminate\Validation\ValidationException;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class CreateOrganizationTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function it_creates_an_organization(): void
{
Queue::fake();
$user = $this->createUser();
$organization = new CreateOrganization(
user: $user,
name: 'Dunder Mifflin',
)->execute();
$expectedSlug = $organization->id . '-dunder-mifflin';
$this->assertInstanceOf(Organization::class, $organization);
$this->assertDatabaseHas('organizations', [
'id' => $organization->id,
'name' => 'Dunder Mifflin',
'slug' => $expectedSlug,
]);
$this->assertDatabaseHas('members', [
'organization_id' => $organization->id,
'user_id' => $user->id,
]);
Queue::assertPushedOn(
queue: 'low',
job: LogUserAction::class,
callback: fn(LogUserAction $job): bool => (
$job->action === 'organization_creation'
&& $job->user->id === $user->id
&& $job->organization->id === $organization->id
&& $job->description === 'Created an organization called Dunder Mifflin'
),
);
}
#[Test]
public function it_rejects_organization_names_with_special_characters(): void
{
$user = $this->createUser();
$this->expectException(ValidationException::class);
new CreateOrganization(
user: $user,
name: 'Dunder & Mifflin',
)->execute();
}
}