0

I was working in laravel 8.x, I have developed API to register, but when i test using postman also in browser the url [1]: http://127.0.0.1:8000/api/register always returns 404 not found message.

below is my api.php

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::group(['prefix' => 'v1'], function () {
    Route::post('/login', 'UsersController@login');
    Route::post('/register', 'UsersController@register');
    Route::get('/logout', 'UsersController@logout')->middleware('auth:api');
});

can you please help?

Olana Kenea
  • 39
  • 2
  • 11

2 Answers2

1

Since you already put a route group "v1", all your routes must have that prefix, so just api/register wont work because that route doesn't exist inside your api.php, so infront of your routes just use

http://127.0.0.1:8000/api/v1/register
http://127.0.0.1:8000/api/v1/login
http://127.0.0.1:8000/api/v1/logout
dz0nika
  • 882
  • 1
  • 5
  • 16
  • This worked perfectly in a browser but when i test on [Postman](https://www.postman.com/) it still returns 404 – Olana Kenea Aug 02 '21 at 11:37
  • You can fix this in two ways, in your authentication tab select basic auth, or sign out your current account and make sure checking Clear Local Data and re-login. Also if that doenst work check out this thread to see a fix, https://stackoverflow.com/questions/36187109/get-request-works-in-browser-but-not-in-postman-or-soapui – dz0nika Aug 02 '21 at 11:40
0

Your routes looking fine. I think you are forgetting to add http://127.0.0.1:8000/api/**v1**/register so please try with it once.