Nida Akram
Nida Akram

Reputation: 362

Missing argument 1 for App\Http\Controllers\DoctorController::edit()

Hey I am making a edit page for user to edit the information but I am getting this error.

Code of controller is:

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]);
}

My route is:

Route::get('doctor/doctorEdit/edit','DoctorController@edit')->name('doctor.edit');

My view is:

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

Please let me know what I am doing wrong.

Upvotes: 0

Views: 534

Answers (3)

Aslam H
Aslam H

Reputation: 1801

Your route doesnt have parameter so change your route.

from this.

Route::get('doctor/doctorEdit/edit','DoctorController@edit')->name('doctor.edit');

to this

Route::get('doctor/doctorEdit/edit/{id}','DoctorController@edit')->name('doctor.edit');

or maybe u want the same method to post

Route::match(['get', 'post'], 'doctor/doctorEdit/edit/{id}','DoctorController@edit')->name('doctor.edit');

Upvotes: 0

Dhiraj
Dhiraj

Reputation: 2767

You are not passing a wildcard (parameter) in your route file.

Change your route, to match a primary key that relates to the specific doctor, it can be a username or simply an id.

 Route::get('doctor/{id}/doctorEdit/edit','DoctorController@edit')->name('doctor.edit');

Make sure you are passing the wildcard appropriately based on your directory

And use that wildcard in your controller

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]);
}

Upvotes: 0

Andrew Brown
Andrew Brown

Reputation: 5424

Because your controller method is accepting a parameter, your route needs to have a parameter in it.

Route::get('doctor/{doctor}/edit','DoctorController@edit')->name('doctor.edit');

Upvotes: 3

Related Questions