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.