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

Naman178's avatar

Laravel API and Web Both in one Application

i am running the web and api in the same project for the web i am usting spetie packge and for the api i am using passport package it working fine but when i run the API at that time its return the html login page in response in laravel so how can i solve that issue

0 likes
10 replies
Sergiu17's avatar

If I understood correctly, then attach Accept: application/json header to the request, after that Laravel will return a proper response for the api

Sergiu17's avatar

@Naman178 now go to the Headers tab and add a new header

Accept application/json

then you will get a json response, with a message instead of login form

1 like
Sergiu17's avatar

@Naman178 now you have to dig in the implementation. maybe you did something wrong. you could share some code

1 like
Naman178's avatar
Naman178
OP
Best Answer
Level 4

@Sergiu17 thanks for your kind help now its working for me

I have added the these 2 lines in the .htaccess file

RewriteCond %{HTTP:Authorization} ^(.*)

RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

elizabetcarr's avatar

If I'm not mistaken, apply the Accept: application/json header to the request, and Laravel will then send a suitable response for the API.

1 like

Please or to participate in this conversation.