check blade file where the delete form is. you declared delete method in web.php but in blade file it was get method and remember this : https://laravel.com/docs/8.x/routing#csrf-protection
Nov 29, 2021
12
Level 1
Delete route don't work with web.php laravel
Hey!! I'm trying to make delete route in web.php like this:
Route::delete('delete/{id}', [App\Http\Controllers\ProductrsController::class, 'destroy']);
This is the controller destroy method :
public function destroy($id)
{
$filepath = 'C:\xampp\htdocs\lec5HW\Products.json';
$fileContent = file_get_contents($filepath);
$jsonContent = json_decode($fileContent, true);
if ($id < 0 || $id > count($jsonContent)) {
return response()->json(['messege' => 'wrong ID'], 400);
}
unset($jsonContent[$id - 1]);
file_put_contents($filepath, json_encode(array_values($jsonContent)));
return response()->json(['messege' => 'Product has been deleted successfully', 'data' => $jsonContent], 200);
}
And I'm getting this error on the browser:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: DELETE.
The same function works on api.php without problems using Postman application. So am I doing something wrong or it's a problem with laravel ??
Please or to participate in this conversation.