Laravel:拒绝路由未定义,但存在于web.php中



我的日历控制器中有一个拒绝函数,但每当我重定向到查看页面时,它都会显示一条错误消息,指出我的路线未定义。

我尝试重新排列和重命名我的路线,但它仍然显示错误。

这是我的表格:

{!! 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);
    }
此按钮所属的视图

页面应该能够显示用于拒绝和完成的按钮以及日历视图。

编辑后续问题:可能是因为路线彼此相似吗?如果是这样,我该如何解决这个问题?

尝试更改拒绝和取消 url 字符串,因为它是相似的。

Route::delete(
    'therapist-calendar/{bookingRequest}/delete',
    'TherapistCalander@rejectAppointment'
)->name('therapist.reject.appointment');
Route::delete(
    'therapist-calendar/{bookingRequest}', 
    'TherapistCalander@cancelAppointment'
)->name('therapist.cancel.appointment');

将代码更改为

    {!! 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() !!}

路由参数作为数组传递,应该可以正常工作。参考文档

你能试试这个代码吗

<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>

更新

问题已修复

我意识到由于他们有类似的链接,网络.php发现它令人困惑,所以它没有阅读这条路线。

这就是为什么我改变了我的路线:

  Route::delete('therapist-calendar/{bookingRequest}',
'TherapistCalander@rejectAppointment')->name('therapist.reject.appointment');

对此:

Route::delete('doReject/{bookingRequest}',
    'TherapistCalander@rejectAppointment')->name('therapist.reject.appointment');

最新更新