Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dippy's avatar
Level 1

Api to create contact

I need to create an api that allows users to create a contact. How can I use laravel's api authentication to develop this api.

0 likes
2 replies
xkrupa12's avatar

If you want to protect API by authentication, just wrap routes into auth:auth middleware that's already present out of the box. If you're using some of the latter versions of Laravel, chances are you've got it prepared already - take a look at routes/api.php.

You might want to do something like:

Route::middleware('auth:api')->group(function () {
    // put your API endpoints here
});
1 like
dippy's avatar
Level 1

Hi xkrupal2, I have created the api and its working fine on my local environment but when I tested on server, it produced 404 error. It worked fine when I tried it through postman but when I called api from another page, it gave 404.

Please or to participate in this conversation.