Пытаюсь сделать что то вроде todo листа, когда пробую сделать удаление, выходит эта ошибка "The DELETE method is not supported for this route. Supported methods: GET, HEAD, POST" Пожалуйста подскажите в чем может быть ошибка, или что проверить и куда копать
index.blade.php
@extends('layouts.app')
@section('title', 'Pupil Page')
@section('content')
@if ($message = Session::get('success'))
<div class="alert alert-success ">
{{ session()->get('success') }}
</div>
@endif
<div class="d-flex justify-content-start">
<a href ="{{ route('pupils.create') }}" class="btn btn-primary" type="submit">Добавить ученика</a>
</div>
<div>
<table class="table mt-3 ">
<thead class="thead-dark">
<tr>
<th scope="col">Фамилия</th>
<th scope="col">Имя</th>
<th scope="col">Отчество</th>
<th scope="col">Дата Рождения</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
@foreach($pupils as $pupil)
<tr>
<td>{{$pupil->surname}}</td>
<td>{{$pupil->name}}</td>
<td>{{$pupil->lastname}}</td>
<td>{{$pupil->birthday}}</td>
<td class = "table-buttons">
<a href = "{{route('pupils.edit', $pupil)}}" class="btn btn-primary">
<i class="fa fa-pencil"></i>
</a>
<form method = "POST" action = "{{ route('pupils.destroy', $pupil) }}">
@csrf
@method('DELETE')
<button type="submit">delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection
web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::resource('pupils', 'PupilsController');
PupilsController.php
<?php
namespace App\Http\Controllers;
use App\Pupils;
use Illuminate\Http\Request;
class PupilsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$pupils = Pupils::all();
return view('pupils.index', compact('pupils'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('pupils.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'surname' => 'required|max:255',
'name' => 'required|max:255',
'lastname' => 'required|max:255',
'birthday' => 'required|max:255',
'address' => 'required|max:255',
]);
$pupils = new Pupils(
[
'surname' => $request->get('surname'),
'name' => $request->get('name'),
'lastname' => $request->get('lastname'),
'birthday' => $request->get('birthday'),
'address' => $request->get('address'),
]
);
$pupils->save();
return redirect('/pupils')->with('success', 'Ученик добавлен!');
}
/**
* Display the specified resource.
*
* @param \App\Pupils $pupils
* @return \Illuminate\Http\Response
*/
public function show(Pupils $pupils)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Pupils $pupils
* @return \Illuminate\Http\Response
*/
public function edit(Pupils $pupils)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Pupils $pupils
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Pupils $pupils)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Pupils $pupils
* @return \Illuminate\Http\Response
*/
public function destroy(Pupils $pupils)
{
$pupils->delete();
return redirect('/pupils')->with('success', 'Ученик удален!');
}
}
https://stackoverflow.com/questions/56293326/the-delete-method-is-not-supported-for-this-route-supported-methods-get-head
, 2)https://laracasts.com/discuss/channels/laravel/the-delete-method-is-not-supported-for-this-route-supported-methods-get-head-post
и т.д. (много в поиске)