Thursday, May 17, 2018

Laravel serve – can’t post - development

Laravel serve – can’t post

I’m trying to build an API and wamp is having issues with the OAuth so I am using Laravel Serve. I am using Laravel 5.3 Passport, each time I POST, the response is blank and doesn’t respond the correct headers (Access-Control-Allow-Origin). It’s also only taking 9MS to get the response (which should be much longer, close to 600MS with PUT). However, if I use PUT, it works correctly.

VUE:

Vue.http.headers.common['Accept'] = 'application/json';
Vue.http.headers.common['Authorization'] = 'Bearer ' + token;

this.$http.post('http://127.0.0.1:8000/api/post/' + this.post.id + '/comment', formData)
            .then(response => {
                console.log(response);
            }, response => {
                // error
            });

Middleware:

protected $middleware = [
   BarryvdhCorsHandleCors::class,
];

protected $middlewareGroups = [
   'api' => [
        'throttle:60,1',
        'bindings',
   ],
]

Route:

Route::group(['middleware' => 'auth:api'], function() {
    // 
    Route::post('/post/{id}/comment, 'ApiPostCommentController@add');
});

Controller:

public function add(Request $request, $post_id)
{
   // 
   return response()->json(['status' => 'success'], 200);
}

Spending a lot of time on something that should just work – any ideas?

Thanks



from Laravel Questions and Answers https://laravelquestions.com/php/laravel-serve-cant-post/
via Lzo Media

No comments:

Post a Comment