Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Result Type

Result Type Laravel Package

graham-campbell/result-type

Result Type is a PHP implementation of the result type, maintained by Graham Campbell. It offers a clean way to represent success or failure values instead of exceptions. Install via Composer with graham-campbell/result-type ^1.1; requires PHP 7.2.5-8.6. MIT licensed.

View on GitHub
Deep Wiki
Context7

Result Type is a lightweight PHP implementation of the result type (also known as Result/Either), maintained by Graham Campbell. It provides a clean, functional way to represent operations that may succeed or fail, helping you avoid exceptions-as-control-flow and making error handling explicit. Requires PHP 7.2.5–8.6 and installs via Composer.

  • Success and Error variants for explicit outcomes
  • Functional operations like map and flatMap for safe chaining
  • Type-safe error handling without throwing exceptions
  • Minimal, dependency-light API
  • MIT licensed with active maintenance and security policy
Frequently asked questions about Result Type
What is graham-campbell/result-type used for?
It is a lightweight, framework-agnostic PHP implementation of the Result type that exposes Ok and Err value objects, letting you represent failure as a returned value instead of a thrown exception. It fits domain and service layers where failure is an expected business outcome, such as payment declines, third-party API rejections, or parsing external payloads. It is not a replacement for Laravel's exception-driven HTTP kernel, validation, middleware, queue retries, or Eloquent.
How do I install graham-campbell/result-type?
Install it with Composer using composer require "graham-campbell/result-type:^1.1". There is no service provider, no config file to publish, and no migrations, so integration cost is effectively zero. The package requires PHP 7.2.5 through 8.6 and pulls in phpoption as a small transitive dependency, so pin and audit your lock file rather than treating it as dependency-free.
Which PHP and Laravel versions does graham-campbell/result-type support?
The package supports PHP 7.2.5 through 8.6 and tracks new PHP releases promptly. Because it is framework-agnostic and contains no Laravel-specific code, it works with any Laravel version running a supported PHP release. Just confirm your Laravel install is compatible with your chosen PHP version.
Is graham-campbell/result-type a replacement for Laravel exceptions?
No. It is a complementary pattern meant to be confined to the service or domain layer, with adapters at the edge that translate to and from exceptions. Laravel's controllers, FormRequests, middleware, jobs, and Eloquent all speak exceptions, and mixing the two paradigms in one call stack produces confusing traces and inconsistent error contracts. If your team cannot enforce that boundary, the package will reduce clarity rather than improve it.
Do I need a service provider or config file for graham-campbell/result-type?
No. It is a plain Composer library with no service provider, no publishable configuration, no migrations, and no runtime hooks. The real adoption cost is convention, adapter code, and refactoring effort, not installation. Greenfield service classes are the cheapest and lowest-risk place to start.
How do I use Ok and Err values in practice?
Your code returns an Ok instance on success and an Err instance on failure, and the caller inspects the result and unwraps it deliberately. Because PHP lacks exhaustive pattern matching on objects, structural equality, and destructuring, a carelessly unwrapped Err becomes a runtime failure, which is exactly the failure mode the pattern exists to prevent. Pair the package with static analysis so ignored results are caught before production.
Can I use Result types in Laravel controllers, models, or jobs?
It is strongly discouraged. Those layers are built around exceptions, so adopting Result there requires translation shims and creates a second, competing error-handling paradigm. The recommended entry point is a greenfield service class or an external-API client in one bounded context, with controllers, models, and jobs explicitly out of scope for the pilot.
Is graham-campbell/result-type well maintained and production ready?
Maintenance risk is genuinely low: it is MIT licensed, has a disciplined changelog and release history, tracks PHP versions promptly, and offers commercial support through Tidelift. The bus factor is one maintainer, but the surface area is small enough to audit and fork in an afternoon. Real-world usage in Laravel applications is thin, with zero dependents and a modest composite score, so a scoped pilot is wiser than a global mandate.
What are alternatives to graham-campbell/result-type?
The main alternative is Laravel's native exception handling, which is the right choice for controllers, validation, middleware, queue retries, and Eloquent. You can also model outcomes with typed error enums, dedicated DTOs, or simple nullable and boolean returns, depending on how much structure your error taxonomy needs. This package suits teams that want a minimal Ok/Err pair without pulling in a larger functional-programming library.
How do I make sure Err values are handled in CI?
Configure PHPStan or Psalm to understand the Ok/Err hierarchy and flag ignored or unwrapped Result values, and treat those findings as CI failures. Without a mechanical gate, the convention will erode quickly under review pressure. Define your error taxonomy for Err, such as string codes, backed enums, or typed error objects, and assign a named owner for the exception-to-Result adapters used around third-party SDKs.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib