Laravel API 404 Error: Customize Exception Message

preview_player
Показать описание
Today I want to talk about Exceptions in Laravel, specifically with the example of API requests and the 404 Not Found case. How to override the non-ideal error message?

- - - - -
Support the channel by checking out our products:
Рекомендации по теме
Комментарии
Автор

Thank you for this. Also you can use the ModelNotFound exception to handle the specifically model not found exceptions

AbdulKudusIssah
Автор

Thanks for the tutorial. Helped me in my production app.

isururanawaka
Автор

Another aproche, if you use try catch you can catch the specific model not found exception, and then customize the return message

TheMarcelitto
Автор

WOW! Thank you so much, your explanation very well! I'll subscribed :)

leslysuarez
Автор

Thank you, this video really helpful to me

kurdev
Автор

i Love it Thanks you are Awesome keep going man ❤️❤️

Mohamadkhalaf
Автор

Práctico y al punto! Me sirvio mucho. Gracias

yuslinandev
Автор

Thank you for your amazing videos. I wish if you can make more videos about API and its advanced tips. Thanks

abdelwahabs.
Автор

I add two macros to the Builder class "findOrFailWithMessage" and "firstOrFailWithMessage".

Builder::macro('findOrFailWithMessage', function (string $id, string $message = null) {

return $this->find($id) ?: abort(404, $message ?: ?: "Resource could not be found");
});

al-aminfirdows
Автор

thanks for all videos.
how to make laravel + vue role based authentication

muhammedrashidp
Автор

Please can you do a tutorial on Laravel Passport, Using it to authenticate React/Vue Api or Mobile App

stancobridge
Автор

please can you tell us the estimated date of release Mobile App with React Native or Flutter and Laravel API tutorial thanks in advance

mohamedhosni
Автор

this video is timely. Please what is the best way to handle validation and other server (5xx) error with API? Thanks

victoronwe
Автор

I have a question. How I can return a json in laravel api, if user is not authenticated ? I use laravel Sactum

alexandresoffiattisantos
Автор

The reason why it sends html if Accept: application/json is not set is because there a bunch of Laravel code that looks like this.
request()->wantsJson() : (send json) ? (send html)

soniablanche
Автор

Thanks for the video. I'm having trouble trying to implement this. I did exactly what you did and always get this response in Postman:
"message": "Attempt to read property \"id\" on null",
"exception": "ErrorException",
What should I do. Thank you.

alexprezmon
Автор

thnax too much, what about error 500 in api, please.

abdelrazeksayedmohmmed
Автор

if we have get /users/{id}/roles/{role_id}, object not found does not provide enough info like weather role is not found or user not found ? how can we solve this ?

parimalbhattarai
Автор

if someone forgots to put accep: application/json on the header, can we do this? - create a middleware and add accept: application/json on the header and apply that middleware to all api. is this way right?

tomjerry-nxdl
Автор

I have a doubt. How could I use this in a test. In order to improve the quality of my application ?

alexandresoffiattisantos