spatie/laravel-error-solutions
Shows helpful, actionable “solutions” directly on Laravel’s error page, explaining likely causes and fixes. Some solutions are runnable with one click (e.g., generate APP_KEY), speeding up debugging during local development.
The easiest way of adding a solution would to implement the ProvidesSolution interface on your exception.
Here's an example that use an anonymous class to implement the Solution interface:
use Exception;
use Spatie\ErrorSolutions\Contracts\Solution;
use Spatie\ErrorSolutions\Contracts\ProvidesSolution;
class ExceptionWithSolution extends Exception implements ProvidesSolution
{
public function __construct(string $message = '')
{
parent::__construct($message ?? 'My custom exception');
}
public function getSolution(): Solution
{
return new class implements Solution
{
public function getSolutionTitle(): string
{
return 'My custom solution';
}
public function getSolutionDescription(): string
{
return 'My custom solution description';
}
public function getDocumentationLinks(): array
{
return [
'Spatie docs' => 'https://spatie.be/docs',
];
}
};
}
}
Of course, you could also use a separate solution class:
use Exception;
use Spatie\ErrorSolutions\Contracts\Solution;
use Spatie\ErrorSolutions\Contracts\ProvidesSolution;
class ExceptionWithSolution extends Exception implements ProvidesSolution
{
public function __construct(string $message = '')
{
parent::__construct($message ?? 'My custom exception');
}
public function getSolution(): Solution
{
return new MySolution();
}
}
How can I help you explore Laravel packages today?