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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners