This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

pratyushpundir6424
pratyushpundir6424

Hi, I'm using vue-resource to make an ajax post request with some data like so:

Vue Code:

onSave: function() {
    this.$http.post('/my/url', JSON.stringify(dataObject));
}

Laravel/OctoberCMS code in routes.php:

Route::post('/my/url/{data}', function($dataObject) {
    Log::info('Route Handler Hit');
    Log::info(json_decode($dataObject)->toArray());
});

There are no PHP or JS errors being thrown. For my Vue instance I also have these options setup, since some people seemed to have trouble without these:

http: {
        emulateJSON: true,
        emulateHTTP: true
}

I'm able to "get" data using the following:

Vue Code:

getData: function() {
    this.$http.get('/some/url', function(data) {
        console.log(data);
    });
}

Laravel/OctoberCMS code in routes.php:

Route::get('/some/url', function() {
    return SomeModel::all()->toArray(); 
});

I can see in chrome that the post request is being made correctly to the correct URL in Chrome devtools but nothing in my route handler callback is being run. Any help will be much appreciated.

Scott
Scott

It might be data parameter in your route. Try registering the vue route to /my/url{/data}, it seems to work for me https://github.com/scottbedard/scottbedard.net/blob/master/assets/js/models/blog/post.js#L15

Last updated

pratyushpundir6424
pratyushpundir6424

@scott - Thanks for the help bud. I just needed to inject 'Request' in my controller method. Everything else I did was good to go. Thanks for taking the time out though. Much appreciated!

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.