ワンクリックで
laravel-exceptions
Custom exceptions with static factories and HTTP responses. Use when creating or modifying exceptions or error handling.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Custom exceptions with static factories and HTTP responses. Use when creating or modifying exceptions or error handling.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Form request validation and comprehensive validation testing. Use when creating or modifying form requests, validation rules, or validation tests.
Feature module pattern organizing domain logic into queries, mutations, and actions. Use when implementing data fetching with filters, API mutations with loading states, business logic with UI feedback, or organizing domain-specific code.
File-based routing with page patterns for lists, details, and navigation. Use when creating pages, defining page meta (permissions, layouts), implementing list/detail patterns, or setting up breadcrumbs and headers.
Foundational architecture for Nuxt 4 + Vue 3 + Nuxt UI applications. Use when starting new projects, understanding project structure, or making architectural decisions about directory organization, technology choices, and pattern selection.
Vue component patterns with Composition API and script setup. Use when creating components, understanding script setup order convention, organizing component directories, or implementing component patterns like slideovers, modals, and tables.
Creating custom Vue composables with proper patterns. Use when building reusable stateful logic, shared state management, or encapsulating feature-specific behavior.
| name | laravel-exceptions |
| description | Custom exceptions with static factories and HTTP responses. Use when creating or modifying exceptions or error handling. |
Custom exceptions use static factory methods and implement HttpExceptionInterface.
Related guides:
<?php
declare(strict_types=1);
namespace App\Exceptions;
use App\Exceptions\Concerns\Httpable;
use App\Models\Order;
use Exception;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
class OrderException extends Exception implements HttpExceptionInterface
{
use Httpable;
public static function notFound(string|int $orderId): self
{
return new self("Order {$orderId} not found.", 404);
}
public static function cannotCancelOrder(Order $order): self
{
return new self(
"Order {$order->uuid} cannot be cancelled in its current state.",
400
);
}
public static function insufficientStock(string $productName): self
{
return new self(
"Insufficient stock for product: {$productName}",
422
);
}
public static function paymentFailed(string $reason): self
{
return new self("Payment failed: {$reason}", 402);
}
}
// In actions
throw OrderException::notFound($orderId);
throw OrderException::cannotCancelOrder($order);
throw OrderException::insufficientStock($product->name);
class CancelOrderAction
{
public function __invoke(Order $order): Order
{
throw_unless(
$order->canBeCancelled(),
OrderException::cannotCancelOrder($order)
);
// Continue with cancellation
}
}
class ProcessOrderAction
{
public function __invoke(Order $order): void
{
$this->guard($order);
// Process order
}
private function guard(Order $order): void
{
throw_unless(
$order->isPending(),
OrderException::cannotProcessOrder($order)
);
throw_unless(
$order->hasItems(),
OrderException::orderHasNoItems($order)
);
}
}
Named constructors for specific exceptions:
public static function notFound(string|int $orderId): self
{
return new self("Order {$orderId} not found.", 404);
}
Pass status as second constructor parameter:
new self("Message", 404); // Not Found
new self("Message", 400); // Bad Request
new self("Message", 422); // Unprocessable Entity
new self("Message", 403); // Forbidden
Include context in error messages:
"Order {$order->uuid} cannot be cancelled"
"Insufficient stock for product: {$productName}"
Implement interface for automatic HTTP error responses:
class OrderException extends Exception implements HttpExceptionInterface
{
use Httpable;
}
400 - Bad Request (business rule violation)402 - Payment Required403 - Forbidden (authorization failed)404 - Not Found422 - Unprocessable Entity (validation failed)500 - Internal Server Errorapp/Exceptions/
├── OrderException.php
├── PaymentException.php
├── UserException.php
└── Concerns/
└── Httpable.php
Exceptions should:
HttpExceptionInterface{Entity}ExceptionUse for business rule violations and error conditions.