working in Laravel 10 project and I am going to insert phone number to table using following LoginController
public function submit(Request $request)
{
$request->validate([
'phone' => 'required|numeric|min:10'
]);
$user = User::firstOrCreate([
'phone' => $request->phone
]);
if(!$user) {
return response()->json(['message' => 'Could not process a user with that Phone number.'], 401);
}
$user->notify(new LoginNeedsVerification());
return response()->json(['message' => 'Text message notification sent.']);
}
my api route is
Route::post('/login', [LoginController::class, 'submit']);
and I am using httpie
command prompt and when I try httpie command as http POST localhost/api/login phone=772541258
cmd got following error msg
Content-Length: 315
Content-Type: text/html; charset=us-ascii
Date: Mon, 08 Jan 2024 05:20:08 GMT
Server: Microsoft-HTTPAPI/2.0
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<hr><p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>
but my data table working properly. it is inset data well. then I need print my json message return response()->json(['message' => 'Text message notification sent.']);
on httpie command pront? then what is the problem?
3
Answers
hope you are doing well.
The blunders you are encountering, HTTP 404 Not Found, suggests that the direction you are trying to access does not exist or is not described on your Laravel application.
In your case, you’re the usage of the subsequent HTTPie command:
Make sure that you are running the command from the correct directory and that your Laravel development server is up and running. Also, ensure that you are using the correct URL for your API endpoint.
If your Laravel development server is running on
localhost
and you are using the default Laravel development server port (8000
), the correct URL should be:Make sure to adjust the URL if you are using a different port.
Additionally, you may want to check if your route is registered correctly by running the following command in your Laravel project directory:
This command will display a list of all registered routes in your Laravel application, and you can check if your
/api/login
route is listed.If the problem persists, please review your Laravel routes and make sure the route is defined in the
web.php
orapi.php
file, depending on your setup. If you still encounter issues, there might be an issue with your Laravel application configuration or server setup.It looks like you’re getting a 404 Not Found error, which means that the route you are trying to access is not defined or not found. The issue might be related to how you are making the HTTP request.
Here’s a correct way to make a POST request using httpie:
Make sure you are using the correct endpoint (/api/login) and that your server is running on localhost. Also, ensure that you are using the correct method (POST).
If you are still facing issues, you can check the following:
web.php
orapi.php
file to ensure itmatches the endpoint you are trying to access.
LoginController
class.If the problem persists, you might want to check your Laravel logs
(storage/logs/laravel.log)
for any additional error messages that could provide more information about the issue.First check the route list with the below command
If you don’t find the your route in list then clear route cache
Here is the code
Now try using postman.It should work.Finally you can use httpie.