1

Hello guy's my I just wrote an delete for my project, it lookes like that:

public function projectdelete(Project $project)
{
    $project->delete();
    return back();
}

My form :

<form action="{{route('project.delete',$project )}}"
    method="POST" 
    onsubmit="return confirm('Are you sure you want to delete the project?')">
    @csrf
    @method('DELETE')
    <button type="submit">Submit</button>
</form>

Route:

Route::delete('/dashboard/project/create/{id}', [
    DashboardController::class, 'projectdelete'
])->name('project.delete');

Why is not deleting it?

2 Answers 2

3

The problem is on the parameter, your route parameter is {id}, on controller you are using Model Binding, for model binding your route parameter name need to be matched with your model {project} :

Route::delete('/dashboard/project/create/{project}', [
    DashboardController::class, 'projectdelete'
])->name('project.delete');
Sign up to request clarification or add additional context in comments.

1 Comment

@m0n0l0g If you were happy that an answer has solved your problem, please mark it as accepted. You can do that by clicking the checkmark / tick underneath the score.
0

In your blade file pass the project parameter as project and also in your routes give your parameter name as project:

My form :

<form action="{{route('project.delete', ['project' => $project])}}" method="POST" onsubmit="return confirm('Are you sure you want to delete the project?')">
    @csrf
    @method('DELETE')
    <button type="submit">Submit</button>
</form>

Route:

Route::delete('/dashboard/project/create/{project}', [DashboardController::class, 'projectdelete'])->name('project.delete');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.