Error: 'The GET method is not supported for this route. Supported methods: PATCH, DELETE.' accessing a route
Error: 'The GET method is not supported for this route. Supported methods: PATCH, DELETE.' accessing a route
我正在做一个 Laravel 项目,我想在其中单击 object(会议)并查看其详细信息,但出现此错误:
laravel error
这是我的 home.blade.php
文件:
<!-- list all the meetings -->
<h3>@lang('Following meetings of '){{ $userName }}</h3>
<div class="row container-fluid">
<div class="row flex-row flex-nowrap position-relative">
@forelse ($meetings as $meeting)
<div class="col-sm-3">
<div class="card card-block zoom">
@csrf
<div class="card-body bg-dark">
<a href="/meeting/{{ $meeting['id'] }}" class="stretched-link text-white">{{ $meeting['name'] }}</a>
</div>
</div>
</div>
@empty
<h4>No tienes reuniones programadas.</h4>
@endforelse
</div>
</div>
</div>
我的web.php
:
// GET
Route::get('/home', [MeetingController::class, 'index'])->name('home');
Route::get('/meeting/{id}', [MeetingController::class, 'show'])->name('meeting.show')->whereNumber('id');
Route::get('/lectures', [LectureController::class, 'index'])->name('lectures');
Route::get('/lectures/{id}', [LectureController::class, 'show'])->name('lectures')->whereNumber('id');
// POST
Route::get('/meeting/create', [MeetingController::class, 'create'])->name('create_meeting');
Route::post('/home', [MeetingController::class, 'store'])->name('meeting.store');
Route::get('/lectures/create', [LectureController::class, 'create'])->name('create_lecture');
Route::post('/lectures', [LectureController::class, 'store'])->name('lecture.store');
// PUT or patch
Route::get('/meeting/edit/{id}', [MeetingController::class, 'edit'])->name('meeting.edit');
Route::patch('/meeting/{id}', [MeetingController::class, 'update'])->name('meeting.update');
// DELETE
Route::delete('/meeting/{id}', [MeetingController::class, 'destroy'])->name('meeting.delete');
还有我的MeetingController.php
public function show($id)
{
//$meeting = Meeting::find($id);
return $id;
}
我认为会议 ID 被检测为字符串。删除 where()
以匹配它,最好使用 route()
生成路由。
文件web.php
:
...
Route::get('/meeting/{id}', [MeetingController::class, 'show'])->name('meeting.show')
...
blade:
<a href="{{ route('meeting.show', $meeting['id']) }}" class="stretched-link text-white">{{ $meeting['name'] }}</a>
我正在做一个 Laravel 项目,我想在其中单击 object(会议)并查看其详细信息,但出现此错误: laravel error
这是我的 home.blade.php
文件:
<!-- list all the meetings -->
<h3>@lang('Following meetings of '){{ $userName }}</h3>
<div class="row container-fluid">
<div class="row flex-row flex-nowrap position-relative">
@forelse ($meetings as $meeting)
<div class="col-sm-3">
<div class="card card-block zoom">
@csrf
<div class="card-body bg-dark">
<a href="/meeting/{{ $meeting['id'] }}" class="stretched-link text-white">{{ $meeting['name'] }}</a>
</div>
</div>
</div>
@empty
<h4>No tienes reuniones programadas.</h4>
@endforelse
</div>
</div>
</div>
我的web.php
:
// GET
Route::get('/home', [MeetingController::class, 'index'])->name('home');
Route::get('/meeting/{id}', [MeetingController::class, 'show'])->name('meeting.show')->whereNumber('id');
Route::get('/lectures', [LectureController::class, 'index'])->name('lectures');
Route::get('/lectures/{id}', [LectureController::class, 'show'])->name('lectures')->whereNumber('id');
// POST
Route::get('/meeting/create', [MeetingController::class, 'create'])->name('create_meeting');
Route::post('/home', [MeetingController::class, 'store'])->name('meeting.store');
Route::get('/lectures/create', [LectureController::class, 'create'])->name('create_lecture');
Route::post('/lectures', [LectureController::class, 'store'])->name('lecture.store');
// PUT or patch
Route::get('/meeting/edit/{id}', [MeetingController::class, 'edit'])->name('meeting.edit');
Route::patch('/meeting/{id}', [MeetingController::class, 'update'])->name('meeting.update');
// DELETE
Route::delete('/meeting/{id}', [MeetingController::class, 'destroy'])->name('meeting.delete');
还有我的MeetingController.php
public function show($id)
{
//$meeting = Meeting::find($id);
return $id;
}
我认为会议 ID 被检测为字符串。删除 where()
以匹配它,最好使用 route()
生成路由。
文件web.php
:
...
Route::get('/meeting/{id}', [MeetingController::class, 'show'])->name('meeting.show')
...
blade:
<a href="{{ route('meeting.show', $meeting['id']) }}" class="stretched-link text-white">{{ $meeting['name'] }}</a>