Laravel 11: Middleware and Exceptions in boostrap/app.php

preview_player
Показать описание
In Laravel 11, there's a new place where you define/configure your Middleware and Exception classes.

- - - - -
Support the channel by checking out my products:

- - - - -
Other places to follow:
Рекомендации по теме
Комментарии
Автор

But I’m worried that if I have a large project, I’ll clutter up this file a lot and I’ll have to somehow take and separate the logic.

L-A-O-S
Автор

I think this approach is better. Of course, you will have to relearn, but in our business you always have to relearn and develop.

L-A-O-S
Автор

I like that everything is in the same place, but hate that the default behaviour is hidden. It makes it seem more like Laravel magic which is bad developer experience. If I want to modify the existing global middlewares, like TrimStrings or VerifyCsrfToken (like the $except array or just modify the handle method), how would I do it now?

dididi
Автор

This looks quite similar to .net core or express.js approach, I like when things converge. Same with VueJS has now hooks like ReactJS.

iedi
Автор

Unless I am blind. I couldn't find anywhere in the official documentation on how do I update my Kernel.php for middleware after upgrading from v10 to v11. The app.php in bootstrap is pretty much still the old format.

errorlade
Автор

I have created API in laravel 11 and i am using auth:api middleware for that, but i don't know how to generate unauthenticated json response if user try to access any protected route and token is not valid (means user is not authenticated).

PankajGupta-hrbg
Автор

bootstrap/app.php

->withExceptions(function (Exceptions $exceptions) {
$exceptions->render(function (NotFoundHttpException $e, Request $request) {
if ($request->is('api/*')) {
return response()->json([
'message' => 'Record not found.'
], 404);
}
});
$exceptions->render(function $e, Request $request) {
if ($request->is('api/*')) {
return response()->json([
'message' => 'Wrong method.'
], 422);
}
});
})->create();

After added this, still get the same error. What else should I do?

cambodiastartupcommunity
Автор

I gotta check the docs cos What if I want add custom commands

codesmiles_