Do you require to delete all data from table using laravel eloquent? If yes then you can get a solution for your problem. We can easily remove all records from table using DB class with delete().

But if you need to destroy all records using laravel eloquent model then how you will do it?, Actually i cache my all records and when someone remove that records then automatic remove from cache too. but it is possible if you are doing with laravel eloquent model. So is there method truncate() with eloquent but it is not working for me, so finally i found solution for delete all records from database table using following way.

Create A Controller.php File and write code for delete..

public function destroy($id)
  {
      $builder=Builder::find($id);
      $builder->delete();
      return 1;
  }

And now add View Code where you will write for delete..

@foreach($builder as $buildername)
      <tr id="pro-{{$buildername->blId}}">
      <td><img src="{{asset('builders_img/'.$buildername->bldlogo)}}" style="width: 115px; height: 60px;"></td>
      <td>{{$buildername->name}}</td>
      <td>{{$buildername->created_at}}</td>
      <td><div class="btn-group">
      <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                      Action <i class="fa fa-angle-down"></i>
      </button>
      <ul class="dropdown-menu">
      <li><a href="{{route('builders.edit', ['builder'=>$buildername->blId])}}">Edit</a></li>
      <li><a href="javascript:void(0)" onclick="deleteProperty({{ $buildername->blId }});">Delete</a></li>
      </ul>
      </div>
      </td>
      </tr>
@endforeach

 

And Now Write JS File add write code for JS…

<script src="{{asset('admin/main/plugins/bootbox/js/bootbox.min.js')}}"></script>
<script type="text/javascript">
  function deleteProperty(id){
    bootbox.confirm("Are you sure?", function(result){
      if(result == true){
        $.ajax({
          url:"{{ url('admin/builders') }}/"+id,
          type:"DELETE",
          headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
          dataType:"JSON",
          success:function(res){
            $('tr#pro-'+id).remove();
            alert("Builder Deleted Successfully");
            window.location.href = "{{route('builders.index')}}";
          }
        });
      }
    });
  }
</script>