evripidesk

html:

<form action="{{action('[email protected]', Hashids::encode($sub['id']))}}" method="POST">
            {{csrf_field()}}
            {{method_field('DELETE')}}
            <button type="submit" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill"
            data-tr="tr_{{$sub['id']}}"
            data-toggle="confirmation"
            data-btn-ok-label="Delete" data-btn-ok-icon="fa fa-remove"
            data-btn-ok-class="btn btn btn-danger"
            data-btn-cancel-label="Cancel"
            data-btn-cancel-icon="fa fa-chevron-circle-left"
            data-btn-cancel-class="btn btn btn-default"
            data-title="Are you sure you want to delete ?"
            data-placement="left" data-singleton="true"
            > <i class="glyphicon glyphicon-trash"></i></button>
          </form>```

Controller
public function destroy($id)
{
  $id=Hashids::decode($id);
  $id = implode(',', $id);

  $sub = Subs::find($id);
  $sub->delete();

  return back()->with('success', 'Subscription Plan has been deleted');

}
v0sn

@evripidesk whats your action and whats your method? You still need to put

<form method="POST">

even tho you are spoofing the method afterwards

evripidesk

sorry for some reason didn't displayed now I edited the post and shows the method

Snapey
Snapey
2 months ago (1,036,705 XP)

You say the error is now when you redirect back? Is the data still valid or did you delete it? ie are you trying to show something that has been deleted?

evripidesk

I make a soft delete function and in my query I am using withTrashed()

Snapey
Snapey
2 months ago (1,036,705 XP)

The problem I think is returning back() If the url for the search was a post then when you do back a get is initiated and this will give an invalid method.

Ideally your search form should be a get

evripidesk

@Snapey thank you so so much, now all are fine!

Please sign in or create an account to participate in this conversation.