Error handling in app/Exceptions/Handler.php.
Logging
Log::info(), Log::error() � logs to storage/logs/.
Custom Exceptions
Create custom exceptions and render in handler.
Error handling in app/Exceptions/Handler.php.
Log::info(), Log::error() � logs to storage/logs/.
Create custom exceptions and render in handler.
Log::info("User logged in", ["user_id" => $user->id]); Log::error("Payment failed", ["order_id" => $order->id]); class PaymentException extends \Exception {} // In handler public function register() { $this->renderable(function (PaymentException $e, $request) { return response()->json(["error" => $e->getMessage()], 422); }); }
try { $payment = Stripe::charges()->create([...]); } catch (CardException $e) { Log::error("Payment declined", ["user" => auth()->id()]); return back()->withErrors(["payment" => "Card declined"]); }
Click Run to see output
No console output yet.
Your changes will be replaced with the original example code.
Create and log a custom exception.
class OrderNotFoundException extends \Exception {}
try {
throw new OrderNotFoundException("Order #999 not found");
} catch (OrderNotFoundException $e) {
Log::error($e->getMessage());
}
Where are Laravel logs stored?
Logs are in storage/logs/.
Use model binding for automatic 404, or abort(404). Custom pages in resources/views/errors/404.blade.php.