Chris
Chris

Reputation: 2181

Laravel delete item from overview

I have a list of my DamagePoint model that I display in a table, my goal is to have a delete button for every item so that you can delete an item from the table.

I have a little problem where I can't seem to get my delete route working. I get the following error:

Type error: Too few arguments to function

Here is my route

Route::delete('pointdelete', 'DamagePointController@delete');

Here is my form

<?php echo Form::open(['url' => '/pointdelete', 'method' => 'delete']) ?>
    <?php echo Form::submit('X'); ?>
<?php echo Form::close() ?>

Here is my controller method

public function delete($id)
{
    $todo = DamagePoint::findOrFail($id);
     $todo->delete();

    return back();
}

Upvotes: 1

Views: 993

Answers (1)

Benjamin Brasseur
Benjamin Brasseur

Reputation: 558

Your delete method use an $id parameter. So your route need to handle it !

Try something like that :

Route

Route::delete('pointdelete/{id}', 'DamagePointController@delete');

View

Replace $yourId by the way you are getting your id

<?php echo Form::open(['url' => '/pointdelete/'.$yourId, 'method' => 'delete']) ?>
    <?php echo Form::submit('X'); ?>
<?php echo Form::close() ?>

Upvotes: 1

Related Questions