Hi and welcome back for another article. I will give you my knowledge on my experience dealing with code that interrupt Laravel's default error handling, and how to mitigate issues that can occur when doing so.

namespace App\Http\Controllers; use App\Models\User; + use Exception; use Illuminate\Http\Request; + use Illuminate\Support\Facades\Log; class UserController { public function create() { return view("user.create"); } public function store(Request $request) { + try { User::create(["name" => $request->string("name")]); + } catch (Exception $exception) { + Log::error($exception->getMessage()); + + return redirect()->back()->withErrors("Unable to store the user."); + } return redirect()->route("user.index")->withSuccess("User stored."); }} #configuring-the-error-handler Configuring the error handler

Now that our error handler is modified, Laravel will automatically handle exception this way: Run through all error handlers (log, Sentry)

That is all I have for today, I hope you will leave with new perspectives in mind after reading this article.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners