0

I am trying to make a DELETE Request to my Laravel API.

I have a todo-App and a tasks.js with a removeTask Method that gets the task object passed as an argument.

removeTask: function(task)
{
    this.tasks.$remove(task);

    this.$http.delete('/api/tasks', { task, 'method': 'DELETE' });
},

Here is what I get in my chrome-dev-tools:

Chrome Dev Tools Screenshot

And this is the destroy Method on my TasksController:

public function destroy(Request $request, $id)
{
    //
    return response()->json(Input::all());
}

Where exactly am I going wrong here?

Thank you in advance.

EDIT

I have a resourceful route looking like this:

Route::get('/', function () {
    return view('pages.tasks.index');
});

Route::group(['prefix' => 'api'], function() {
    Route::resource('tasks', 'TasksController');
});
1
  • You need a route set up in your routes file. do you have this? Commented Aug 5, 2015 at 16:05

2 Answers 2

1

Set a route in laravel's routes.php file like this:

Route::delete('api/tasks', 'TasksController@destroy');
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I had a route. Found the problem. Had forgot to pass the id to the route. Works like charm now.
0

Error was in the removeTask method with Vue:

removeTask: function(task)
{
    this.tasks.$remove(task);

    this.$http.delete('/api/tasks', { task, 'method': 'DELETE' });
},

Should have had this:

removeTask: function(task)
{
    this.tasks.$remove(task);

    this.$http.delete('/api/tasks/' + task.id, task);
},

Didn't pass in the id, like my resourceful route suggested.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.