Search code examples
phplaravellaravel-7

send entity for controller not working, php laravel 7


in blade template

<form action="{{ route('leads.courses.restore', $lead->id) }}" method="POST">
  @csrf
  <button type="submit">
    Restore 
  </button>
</form>

in routes

Route::post('leads/courses/{lead}/restore', 'LeadsCoursesController@restore')->name('leads.courses.restore');

in controller

public function restore(Lead $lead)
  {
    dd("ok");
  }

but i receive HTTP code 404, if i remove the parameter in controller receive "ok".


Solution

  • This problem happens because you try to find a soft deleted record so to fix it add to your route withTrashed() to be like this

    Route::post('leads/courses/{lead}/restore', 'LeadsCoursesController@restore')
       ->withTrashed()
       ->name('leads.courses.restore');
    

    for more info check this part in docs