如何在laravel 5.2中编辑和删除页面?

时间:2016-11-14 06:24:40

标签: laravel-5.2

当我尝试编辑和删除员工时,会显示错误。
删除

Missing argument 1 for App\Http\Controllers\Admin\CreateEmployeeController::deleteemployee()

用于编辑

Missing argument 1 for App\Http\Controllers\Admin\CreateEmployeeController::editemployee()

方法:

public function editemployee($id)
{
   $employee = CreateEmployee::where('id',$id)->get();

   return view('app.admin.employee.editemployee',compact('employee'));
}

public function updateemployee(Request $request)
{

  CreateEmployee::where('id',$request->id)->update(array('username'=>$request->username,'area'=>$request->area_name));

  Session::flash('flash_notification', array('level' => 'success', 'message' => 'channel details updated successfully'));

  return Redirect::action('Admin\CreateEmployeeController@addemployee',array('id' => $request->id));

}


public function deleteemployee($id)
{

    $employee =  CreateEmployee::where('id',$id)->get();

    return view('app.admin.employee.deleteemployee',compact('employee'));
}


public function deleteconfirms($id)
{

     $employee = CreateEmployee::where('id',$id)->delete();

     Session::flash('flash_notification', array('level' => 'success', 'message' => 'employee deleted successfully'));

     return Redirect::action('Admin\CreateEmployeeController@addemployee');

}

1 个答案:

答案 0 :(得分:1)

我可以看到您的方法deleteemployeedeleteconfirmseditemployee期待id字段。 在您的路线中,您没有使用任何"路线参数" (详见Route Parameters) 因此,更改您的路线以包括路线参数,如下所示。其中id代表employee_id

Route::get('edit-employee/{id}','CreateEmployeeController@editemp‌​loyee');
Route::post('update-employee','CreateEmployeeController@upd‌​ateemployee');
Route::get('delete-employee/{id}','CreateEmployeeController@delet‌​eemployee');
Route::post('delete-confirms/{id}','CreateEmployeeController@dele‌​teconfirms');