phplaravel-5laravel-routingrestful-architecture

Laravel 5 POST routes to index instead of store


I am working on a Laravel 5 RESTful API that seems not to be routing the POST requests correctly.

This is my routes.php:

Route::group(array('prefix' => 'api/v1'), function()
{
    Route::resource('messages', 'IncomingMessages');
});

And this is my controller:

class IncomingMessages extends Controller
{   
    public function index() {
        return "This is index";
    }

    public function store() {
        return "This is store";
    }

    public function update() {
        return "This is update";
    }
}

And this is what happens:

This is what php artisan route:list returns:

So, my question is:

What am I missing? Why is it routing to index() instead of routing to store()?

NOTES:

UPDATE:

The problem was adding a trailing / to the URL. So, instead of using this URL:

mydomain.com/api/v1/messages/

I tried with this one:

mydomain.com/api/v1/messages

and it worked


Solution

  • The problem was caused by a trailing / being added to the URL. So, instead of using this URL:

    mydomain.com/api/v1/messages/

    I tried with this one:

    mydomain.com/api/v1/messages

    and it worked.

    I discovered it by taking a look at the server's log. That is how I discovered that POST requests to the URL messages/ were redirected.