in Education by
I am trying to create authentication using Laravel Passport, I have configured everything the right way as mentioned in the official documentation. The GET Route method works perfectly (see the code below), but when I try the POST Route method I always get this error: The POST method is not supported for this route. Supported methods: GET, HEAD. P.S: I am using Postman for the test. I have tried to include CSRF token but nothing happens, and I get the same error. Controller class AuthController extends Controller { public function register(Request $request) { $validator = Validator::make($request->all(), [ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:6|confirmed', ]); if ($validator->fails()) { return response(['errors' => $validator->errors()->all()], 422); } $request['password'] = Hash::make($request['password']); $user = User::create($request->toArray()); $token = $user->createToken('Laravel Password Grant Client')->accessToken; $response = ['token' => $token]; return response($response, 200); } public function login(Request $request) { $user = User::where('email', $request->email)->first(); if ($user) { if (Hash::check($request->password, $user->password)) { $token = $user->createToken('Laravel Password Grant Client')->accessToken; $response = ['token' => $token]; return response($response, 200); } else { $response = "Password missmatch"; return response($response, 422); } } else { $response = 'User does not exist'; return response($response, 422); } } public function logout(Request $request) { $token = $request->user()->token(); $token->revoke(); $response = 'You have been succesfully logged out!'; return response($response, 200); } } Routes Route::middleware('auth:api')->get('/user', function (Request $request) { return $request->user(); }); Route::post('/login', 'Api\AuthController@login')->name('login.api'); Route::post('/register', 'Api\AuthController@register')->name('register.api'); I expect to get user registered, and it returns the auth token, but it shows me "The POST method is not supported for this route. Supported methods: GET, HEAD." JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This line should be in api.php Route::middleware('auth:api')->get('/user', function (Request $request) { return $request->user(); });

Related questions

0 votes
    How to turn off CRSF protection for specific route in Laravel?...
asked Sep 30, 2021 in Technology by JackTerrance
0 votes
    I'm pretty new at laravel, in fact and I'm trying to create my very first project. for some ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I'm trying to make a post request via jquery but It seems to be something wrong. Route: Route:: ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm trying to make a post request via jquery but It seems to be something wrong. Route: Route:: ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Why do we use Route in laravel?...
asked Sep 28, 2021 in Technology by JackTerrance
0 votes
    What is a Route in laravel?...
asked Sep 28, 2021 in Technology by JackTerrance
0 votes
    I'm trying to populate a database using seeder. I get an error: SQLSTATE[23000]: Integrity constraint ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    Running VS2003/05 under Vista makes the former screw up the display at least 50% of the time - you ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Running VS2003/05 under Vista makes the former screw up the display at least 50% of the time - you ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Running VS2003/05 under Vista makes the former screw up the display at least 50% of the time - you ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    I had a program working good (without prompting errors) using references, but I decided to use a pointer-to-pointer array ... that it is there because I have put two flags (cout...
asked Apr 6, 2022 in Education by JackTerrance
0 votes
    I am debugging a Service Fabric application and need to use a conditional breakpoint based on the value of ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I am working on vs 2010 and EF 4.1 with SQL server database. Below mentioned code works fine with local SQL ... , Func`1 continuation) Select the correct answer from above options...
asked Feb 3, 2022 in Education by JackTerrance
...