Add solutions to exceptions
mainIgnition can display actionable solutions for errors. There are two ways to implement this:
1. Implementing ProvidesSolution on an Exception
Make your custom exception implement the Spatie\Ignition\Contracts\ProvidesSolution interface. You must implement the getSolution() method, which returns an instance of Spatie\Ignition\Contracts\Solution.
2. Using Solution Providers
For more complex logic (like looking up solutions on Stack Overflow), implement the Spatie\Ignition\Contracts\HasSolutionsForThrowable interface. This allows you to decide if a provider can solve a specific Throwable via canSolve() and then return the solutions via getSolutions().
Register providers using addSolutionProviders().
// Implementing a solution directly in an exception
use Spatie\Ignition\Contracts\Solution;
use Spatie\Ignition\Contracts\ProvidesSolution;
class CustomException extends Exception implements ProvidesSolution
{
public function getSolution(): Solution
{
return new CustomSolution();
}
}
class CustomSolution implements Solution
{
public function getSolutionTitle(): string
{
return 'The solution title goes here';
}
public function getSolutionDescription(): string
{
return 'This is a longer description of the solution that you want to show.';
}
public function getDocumentationLinks(): array
{
return [
'Your documentation' => 'https://your-project.com/relevant-docs-page',
];
}
}
// Registering a solution provider
\Spatie\Ignition\Ignition::make()
->addSolutionProviders([
YourSolutionProvider::class,
])
->register();