Search code examples
phplaravel-5.1laravel-routingdingo-api

Laravel route works perfectly locally but not on remote. (Dingo Api)


I am using dingo/api for a project and all of my routes work other than 1.

routes.php

    $api = app('api.router');
    $api->version('v1',['prefix' => 'api'], function ($api) {

        $api->post('users', "App\Http\Controllers\Auth\UsersController@store");
...
        });

store method :

/**
     *
     * @param  \App\Http\Requests\Auth\StoreUserRequest  $request
     * @return \Illuminate\Http\Response
     */
    public function store(StoreUserRequest $request)
    {
        if( ! $this->isAdminRequest() )
        {
            return $this->dispatch(new RegisterUserCommand($request));
        }
    }

This route throws 405 Method Not Allowed Exception.

php artisan api:routes shows that it is registered, both locally and on server. I am using POSTMAN to test my api and have all required fields. In response I do get Allow : POST.

NOTE :

  • There are other post routes that work perfectly.
  • There are other UsersController routes that work perfectly
  • I have tried removing all other routes and with just this, it still does not work.

Any help is appreciated. Thanks.

UPDATE :

Okay, it was a really silly mistake on my part. I was hitting 'domain/api/users/'. Removing the trailing '/' worked. But the thing is, locally '/' works and not on server. So keeping this question on for some explanantion maybe.


Solution

  • Very good question and have since ran into this myself. Your update should be in an answer so if you do that, I may remove mine. The problem for me was a trailing slash in my action e.g. /some/action/ instead of /some/action where the route expected it in the latter form.

    I had assumed that Laravel would handle this optional trailing slash as a feature considering the behaviour in a local environment but this was not the case.