.cursor/skills/laravel-actions/references/object.md
run, make, DI)Use this reference when the action is invoked as a plain object.
make, run, runIf, runUnless.handle(...).handle(...).Action::run(...) for readability.Action::make()->handle(...) or DI only when needed.makeResolves the action from the container.
PublishArticle::make();
// Equivalent to:
app(PublishArticle::class);
runResolves and executes the action.
PublishArticle::run($articleId);
// Equivalent to:
PublishArticle::make()->handle($articleId);
runIfResolves and executes the action only if the condition is met.
PublishArticle::runIf($shouldPublish, $articleId);
// Equivalent mental model:
if ($shouldPublish) {
PublishArticle::run($articleId);
}
runUnlessResolves and executes the action only if the condition is not met.
PublishArticle::runUnless($alreadyPublished, $articleId);
// Equivalent mental model:
if (! $alreadyPublished) {
PublishArticle::run($articleId);
}
handle(...) has no transport concerns.handle(...) tests.handle(...).handle(...) instead of the reverse.final class PublishArticle
{
use AsAction;
public function handle(int $articleId): bool
{
// Domain logic...
return true;
}
}
$published = PublishArticle::run(42);
final class ArticleService
{
public function __construct(
private PublishArticle $publishArticle
) {}
public function publish(int $articleId): bool
{
return $this->publishArticle->handle($articleId);
}
}