Replies: 1 comment
-
You are missing On an HTTP Request:
( By default, Laravel will return HTML when no Actually, when the To force all <?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class EnsureJsonResponseForApi
{
public function handle(Request $request, \Closure $next): Response
{
if ($request->is('api/*')) {
$request->headers->set('Accept', 'application/json');
}
return $next($request);
}
} Or add a similar one, that always sets the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
9.52.20
PHP Version
8.0.2
Database Driver & Version
my sql version 10.4.17-MariaDB (xampp phpmyadmin)
Description
Steps to Reproduce:
Open Postman and create a new POST request.
Set the URL to http://127.0.0.1:8000/api/admin/register.
Set the Headers:
Content-Type: application/json
Set the Body (JSON):
{ "name": "Admin Name", "email": "[email protected]", "password": "password", "password_confirmation": "password" }
Send the request.
Expected Result: A JSON response indicating successful registration:
{ "message": "Admin registered successfully" }
Actual Result: The default Laravel welcome page is returned.
relevant files and code:
routes/api.php
app/Http/Controllers/AdminAuthController.php
app/Providers/RouteServiceProvider.php
.env
Please provide any insights or suggestions on why the API request is returning the Laravel welcome page instead of the expected JSON response. Any help in identifying the root cause and resolving this issue would be greatly appreciated.
Steps To Reproduce
.
Beta Was this translation helpful? Give feedback.
All reactions