PHP code example of jftecnologia / laravel-exceptions
1. Go to this page and download the library: Download jftecnologia/laravel-exceptions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jftecnologia / laravel-exceptions example snippets
use JuniorFontenele\LaravelExceptions\Facades\LaravelException;
return Application::configure(basePath: dirname(__DIR__))
// ... other configurations
->withExceptions(function (Exceptions $exceptions) {
// ... other exception handlers
// Register Laravel Exceptions handler (must be the last handler)
LaravelException::handles($exceptions);
})
->create();
use JuniorFontenele\LaravelExceptions\Facades\LaravelException;
return Application::configure(basePath: dirname(__DIR__))
// ... other configurations
->withExceptions(function (Exceptions $exceptions) {
// ... other exception handlers
// Register Laravel Exceptions handler (must be the last handler)
LaravelException::handles($exceptions);
})
->create();
use JuniorFontenele\LaravelExceptions\Exceptions\AppException;
// Basic exception
throw new AppException(
message: 'Internal system error',
userMessage: 'An error occurred. Please try again.',
statusCode: 500
);
// With additional context
throw new AppException(
message: 'Payment processing failed',
userMessage: 'Unable to process payment.',
statusCode: 422,
context: [
'payment_id' => $paymentId,
'amount' => $amount,
]
);
use JuniorFontenele\LaravelExceptions\Exceptions\Http\NotFoundHttpException;
use JuniorFontenele\LaravelExceptions\Exceptions\Http\UnauthorizedHttpException;
throw new NotFoundHttpException('Resource not found');
throw new UnauthorizedHttpException('Access denied');
use Illuminate\Support\Facades\Schedule;
Schedule::command('laravel-exceptions:clean --force')
->daily()
->onOneServer();