Laravel directing HTTP method to wrong function in Controller

Asked

Viewed 128 times

0

I have a project in Laravel and Vue.js where I have a role in Vue.js that sends a post with the data of a form, so far so good, only when the function this.$http.post() makes the request for the back-end, the Variable directs to the wrong method, it should send to the method store(that handles post requests), but sends to index method(responsible for GET requests), one detail is that I am using RestFull Controllers, then all methods are being accessed based on the request being made(or at least it should be so).

One detail is that locally in the machine that I use to develop works perfectly, and in another local server machine, also works perfectly, now put this project in the Amazon production server happens what I reported above.

The settings are as follows::

Local machine

PHP 5.6.28


Local Server

PHP 7.0


Amazon Server(EC2)

PHP 5.6.30


What could be going on? I’ve really thought of several possibilities and I have no idea what it might be.

  • 2

    Edit the question and add the codes referring to the problem, such as the JS code that makes the request and the code of the Laravel controller that has the methods index and store.

2 answers

0

It turns out that when working with Vueresource, in some projects you need to tell it to emulate a normal request like HTTP.

To perform this configuration, add the Configs parameter to Vueresource, it would look like this:

var config = {
    emulateJSON: true,
    emulateHTTP: true
};

// Adicionado o CONFIG para emular
this.$http.post(url, data, config).then((val) => {
    console.log(val);
});
  • In the http methods already includes the above settings, but without the HTTP emulator, I tried with and did not help either.

0


I found the solution, I actually found the answer in the foreign forum, what was happening was that the url in the $http methods were with a "/"(bar) at the end, for example: "test.com/api/v1/Resource/"

I was just taking it off like this: "test.com/api/v1/Resource"

making it work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.