1
votes

I'm using laravel 5.8 and this is my routes/api.php file.

Route::get('/tasks', 'TaskController@index')->name('tasks.index');
Route::post('/tasks', 'TaskController@store')->name('tasks.store');
Route::get('/tasks/{task}', 'TaskController@show')->name('tasks.show');
Route::put('/tasks/{task}', 'TaskController@update')->name('tasks.update');
Route::delete('/tasks/{task}', 'TaskController@destory')->name('tasks.destroy');

And this is function destroy() inside TaskController,

public function destroy(Task $task)
{
    $task->delete();

    return response()->json([
        'message' => 'Successfully deleted task!'
    ]);
}

But when I call the function I get this error,

BadMethodCallException Method App\Http\Controllers\TaskController::destory does not exist.

1
Your message refers to destory your code shows a method destroy. Note that the "o" and the "r" are in different orders.Dragonthoughts

1 Answers

1
votes

I hope it's not the typo.

You are basically calling a function destory but your controller function name is destroy
Should be fixed by making it the same.

Route::delete('/tasks/{task}', 'TaskController@destroy')->name('tasks.destroy');