我的“日历”控制器中有一个拒绝功能,但是每当我重定向到视图页面时,都会显示一条错误消息,提示未定义我的路线。
我尝试重新排列和重命名路线,但仍显示错误。
这是我的表格:
{!! Form::open(['url' => route('therapist.reject.appointment', $bookingRequest), 'method' => 'delete', 'onsubmit' => 'javascript:return confirm("Are you sure?")']) !!}
<button type="submit" class="btn btn-warning btn-block">Reject this appointment</button>
{{csrf_field()}}
{!! Form::close() !!}
这是我的路线。显示的其他路线运行正常:
Route::get('therapist-calendar/{bookingRequest}', 'TherapistCalander')->name('therapist.calendar');
Route::post('therapist-calendar/{bookingRequest}',
'TherapistCalander@saveAppointment')->name('therapist.book.appointment');
Route::patch('therapist-calendar/{bookingRequest}',
'TherapistCalander@finishedAppointment')->name('therapist.finish.appointment');
Route::delete('therapist-calendar/{bookingRequest}',
'TherapistCalander@rejectAppointment')->name('therapist.reject.appointment');
Route::delete('therapist-calendar/{bookingRequest}',
'TherapistCalander@cancelAppointment')->name('therapist.cancel.appointment');
最后,我的功能:
public function rejectAppointment(Request $request, BookingRequest $bookingRequest)
{
$bookingRequest->reject();
return redirect()->back()->with('rejectStatus', true);
}
此按钮所属的视图页面应该能够在日历视图旁边显示用于拒绝和完成的按钮。
编辑 后续问题:是否可能是因为路线彼此相似?如果是这样,我该如何解决?
答案 0 :(得分:2)
请尝试更改“拒绝”和“取消” URL字符串,因为它很相似。
Route::delete(
'therapist-calendar/{bookingRequest}/delete',
'TherapistCalander@rejectAppointment'
)->name('therapist.reject.appointment');
Route::delete(
'therapist-calendar/{bookingRequest}',
'TherapistCalander@cancelAppointment'
)->name('therapist.cancel.appointment');
答案 1 :(得分:0)
将代码更改为
{!! Form::open(['url' => route('therapist.reject.appointment', ['bookingRequest' => $bookingRequest]), 'method' => 'delete', 'onsubmit' => 'javascript:return confirm("Are you sure?")']) !!}
{{csrf_field()}}
<button type="submit" class="btn btn-warning btn-block">Reject this appointment</button>
{!! Form::close() !!}
route参数作为数组传递,应该可以正常工作。请参阅doc
您可以尝试使用此代码
<form action="{{ route('therapist.reject.appointment', ['bookingRequest' => $bookingRequest]) }}" method="POST">
@method('DELETE')
@csrf
<button type="submit" class="btn btn-warning btn-block">Reject this appointment</button>
</form>
答案 2 :(得分:0)
更新
已解决问题
我意识到由于它们具有相似的链接,因此web.php使其感到困惑,因此它没有阅读此路由。
这就是为什么我更改路线的原因:
Route::delete('therapist-calendar/{bookingRequest}',
'TherapistCalander@rejectAppointment')->name('therapist.reject.appointment');
对此:
Route::delete('doReject/{bookingRequest}',
'TherapistCalander@rejectAppointment')->name('therapist.reject.appointment');