0

I have a route in api.php which look like this:

Route::get('auth/logout/{token}','UserController.php';

I tested this API endpoint using Postman with these configurations:

  • Method: GET
  • Params: key = token; value = $2y$10$Xji0VW1Qq9rtF04QlXDu1ePKNKHpRA2ppjDYWNFX.37C30sd3WSIu
  • Header: none
  • URL: localhost:8000/api/v1/logout?token=$2y$10$Xji0VW1Qq9rtF04QlXDu1ePKNKHpRA2ppjDYWNFX.37C30sd3WSIu

Here is my UserController@logout:

public function logout($token){
    return response()->json([
        'message' => 'Logout Success',
        'token' => $token
    ], 200);
}

As you can see there, I just want to show a message and the $token parameter in Postman. But my problem is, Postman shows me a blank response. I can't access the URL with ? as the parameter separator. But I can access the URL with /, just like host/api/v1/auth/logout/{token_value}. But it is not what I desired. Anyone can help me?

1 Answer 1

2

You can remove the token route parameter:

Route::get('auth/logout', 'UserController.php');

And retrieve the token from the request in the controller:

public function logout(Request $request) {
    return response()->json([
        'message' => 'Logout Success',
        'token' => $request->token
    ], 200);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Oh, dude!!! Thanks a lot! This is what I searched for. Thanks, @Remul. I am sorry for my edit.
@DaniFadli You can type-hint the request like it is now, or use the request('token') helper function, both work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.