mikefolu
mikefolu

Reputation: 1333

Laravel - Submit button in delete modal form not responding

I am using Laravel-5.8 for a web application project. All other parts of the CRUD is working except the delete.

Controller

public function destroy(Request $request, $id)
{
    $group = HrHolidayGroup::find($id);
    $group->delete();
    Session::flash('success', 'Holiday Group deleted successfully.');
    return redirect()->route('hr.holiday_groups.index');
}

route/web

Route::group(['prefix' => 'hr', 'as' => 'hr.', 'namespace' => 'Hr', 'middleware' => ['auth']], function () {

Route::resource('holiday_groups', 'HrHolidayGroupsController');

});

index.blade.php

<tbody>
 @foreach($groups as $key => $group)
<td>
 {{$key+1}}
</td>
<td>
  {{$group->group_name ?? '' }}
</td>
<td>
  {{ $group->description ?? '' }}
</td>
<td>
    @can('holiday_group_delete')
<a class="btn btn-xs btn-danger" data-toggle="modal" data-target="#confirm-delete{{ $group->id }}" data-original-title="Close"> 
 span style="color:white;">{{ trans('global.delete') }}</span>
</a>
    @endcan
                            
 <div class="modal fade" id="confirm-delete{{ $group->id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
 <div class="modal-dialog">
   <div class="modal-content">
     <div class="modal-header">
      <h4 class="modal-title">Delete Holiday Group</h4>
      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
       <span aria-hidden="true">&times;</span>
      </button>
     </div>
    <div class="modal-body">
     <form action="{{route('hr.holiday_groups.destroy',['id'=>$group->id])}}" method="post">
     {{ csrf_field() }}
      <p>Are you sure you want to delete this Holiday Group?</p>
      <div class="modal-header">
      <h4>{{ $group->group_name }}</h4>
     </div>
     </form>
    </div>
    <div class="modal-footer justify-content-between">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <button type="submit" class="btn btn-danger">Delete</button>
     </div>
      </div>
      <!-- /.modal-content -->
      </div>
    <!-- /.modal-dialog -->
   </div>
  <!-- /.modal -->  
 </td>
                                           
</tr>
@endforeach 

delete dialogue diagram

When I clicked on Delete button on the modal form in the diagram, nothing happened. It just remain on the screen and no action is performed.

How do I get this resolved?

Thank you.

Upvotes: 0

Views: 517

Answers (1)

albus_severus
albus_severus

Reputation: 3712

Try this

<form action="{{route('hr.holiday_groups.destroy',['id'=>$group->id])}}" method="post">
     {{ csrf_field() }}
     {{method_field('DELETE')}}
      <p>Are you sure you want to delete this Holiday Group?</p>
      <div class="modal-header">
      <h4>{{ $group->group_name }}</h4>
     </div>
     <button type="submit" class="btn btn-danger">Delete</button>
</form>
public function destroy($id)
{
    $group = HrHolidayGroup::find($id);
    $group->delete();
    Session::flash('success', 'Holiday Group deleted successfully.');
    return redirect()->route('hr.holiday_groups.index');
}

Upvotes: 1

Related Questions