user3718908x100
user3718908x100

Reputation: 8509

Controller Method Not Found Strange Behaviour

I have an AuthController in my laravel app, inside that controller i have several methods:

public function postLogin(LoginRequest $request)
{
  ...
}

public function getRegister()
{
  ...
}

public function postRegister(RegisterRequest $request)
{
  ...
}

For some reason now my postRegister() function does not work, when I run it in postman for some reason it always executes getRegister() instead, when i take out getRegister() it says Controller method not found.

This is my route:

Route::group(['prefix' => '/api/v1/', 'namespace' => 'App\Http\Auth\Controllers'], function() {
    /**
     * Authentication
     */
    Route::controllers([
        'auth' => 'AuthController',
        'password' => 'PasswordController',
    ]);
});

Edit: I have narrowed the issue down to my request file, the path is correct but for some reason when i try to use it in postRegister(RegisterRequest $request), the postRegister function does not get executed, no errors are thrown, it worked before now i have no idea what is causing this issue now.

I think i should also add that i created custom namespaces which i am using in my application.

Upvotes: 0

Views: 150

Answers (2)

user3718908x100
user3718908x100

Reputation: 8509

After hours of searching and changing my code i found a solution here: laracasts.com/discuss/channels/laravel/laravel-5-custom-request-not-working

Apparently when using postman to test your APIs in laravel you need to set the AcceptHeader to Application/json. I did not know this. :)

Upvotes: 0

lagbox
lagbox

Reputation: 50491

Make sure in Postman you are setting the HTTP method to 'POST', you are probably using 'GET' which is hitting the 'get' route not the 'post' route.

You can do a php artisan route:list to see your actual routes and the HTTP method(s) they accept.

Upvotes: 1

Related Questions