2017-10-04 62 views
0

嘿,我正在爲用戶編輯信息編輯頁面,但我收到此錯誤。控制器的App Http Controllers DoctorController缺少參數1 :: edit()

代碼是:

public function edit($id) 
{ 
    $doctor = Doctor::find($id); 
    // Redirect to state list if updating state wasn't existed 
    if ($doctor == null || count($doctor) == 0) { 
     return redirect()->intended('doctor/doctorList'); 
    } 
    return view('doctor/doctorEdit', ['doctor' => $doctor]); 
} 

我的路線爲:

Route::get('doctor/doctorEdit/edit','[email protected]')->name('doctor.edit'); 

我的觀點是:

<a href="{{ route('doctor.edit', ['id' => $doctor->id]) }}" class="btn btn-warning col-sm-3 col-xs-5 btn-margin" style="width:100px; margin-left:20px;"> 
        Update 
        </a> 

P租賃讓我知道我做錯了什麼。

回答

0

你是不是在你的路線將文件傳遞一個通配符(參數)。

更改您的路線,以匹配與特定醫生相關的主鍵,它可以是用戶名或簡稱爲ID。

Route::get('doctor/{id}/doctorEdit/edit','[email protected]')->name('doctor.edit'); 

確保您通過適當根據您的目錄

,並使用通配符通配符在控制器

public function edit($id) 
{ 
    $doctor = Doctor::where('id', $id)->first(); 
    // Redirect to state list if updating state wasn't existed 
    if ($doctor == null || count($doctor) == 0) { 
     return redirect()->intended('doctor/doctorList'); 
    } 
    return view('doctor/doctorEdit', ['doctor' => $doctor]); 
} 
0

您的路線不必須的參數,從而改變你的路線。

這個。

Route::get('doctor/doctorEdit/edit','[email protected]')->name('doctor.edit'); 

這個

Route::get('doctor/doctorEdit/edit/{id}','[email protected]')->name('doctor.edit'); 

或者也許ü想同樣的方法來發布

Route::match(['get', 'post'], 'doctor/doctorEdit/edit/{id}','[email protected]')->name('doctor.edit'); 
相關問題