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.
If you want to add solutions to exceptions that you can't modify, you can use a solution provider. A solution provider is a class that implements the ProvidesSolution interface. It will determine if it can provide a solution for a given exception.
Here's an example:
use Spatie\ErrorSolutions\Contracts\HasSolutionsForThrowable;
use Spatie\ErrorSolutions\Contracts\Solution;
use Throwable;
class YourSolutionProvider implements HasSolutionsForThrowable
{
public function canSolve(Throwable $throwable): bool
{
// return true if you can provide a solution for this exception
}
/**
* [@param](https://github.com/param) \Throwable $throwable
*
* [@return](https://github.com/return) array<int, Solution>
*/
public function getSolutions(Throwable $throwable): array
{
// return an array of solutions
}
}
After you've created your solution provider, you can register it in the solution_providers key of the error-solutions.php config file:
// config/error-solutions.php
return [
'solution_providers' => [
// other solution providers
YourSolutionProvider::class,
],
];
Alternatively, you can register your solution provider at runtime. Typically, this would be done in a service provider:
// app/Providers/YourServiceProvider.php
use Spatie\ErrorSolutions\ErrorSolutionsServiceProvider;
use Spatie\ErrorSolutions\Contracts\SolutionProviderRepository;
public function register()
{
$repository = app(SolutionProviderRepository::class);
$repository->registerSolutionProviders([
YourSolutionProvider::class,
]);
}
How can I help you explore Laravel packages today?