Janith ashen
Janith ashen

Reputation: 57

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

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.

Upvotes: 2

Views: 1026

Answers (1)

fmsthird
fmsthird

Reputation: 1875

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');

Upvotes: 1

Related Questions