Skip to content

Commit

Permalink
create delete record teacher
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeng Souy committed May 1, 2023
1 parent 6d31c57 commit c412cf0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
17 changes: 17 additions & 0 deletions app/Http/Controllers/TeacherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,21 @@ public function updateRecordTeacher(Request $request)
return redirect()->back();
}
}

/** delete record */
public function teacherDelete(Request $request)
{
DB::beginTransaction();
try {

Teacher::destroy($request->id);
DB::commit();
Toastr::success('Deleted record successfully :)','Success');
return redirect()->back();
} catch(\Exception $e) {
DB::rollback();
Toastr::error('Deleted record fail :)','Error');
return redirect()->back();
}
}
}
49 changes: 43 additions & 6 deletions resources/views/teacher/list-teachers.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

@extends('layouts.master')
@section('content')

{{-- message --}}
{!! Toastr::message() !!}
<div class="page-wrapper">
<div class="content container-fluid">
<div class="page-header">
Expand Down Expand Up @@ -90,6 +91,7 @@ class="fas fa-download"></i> Download</a>
value="something">
</div>
</td>
<td hidden class="id">{{ $list->id }}</td>
<td>{{ $list->user_id }}</td>
<td>
<h2 class="table-avatar">
Expand All @@ -111,17 +113,16 @@ class="fas fa-download"></i> Download</a>
<td>{{ $list->address }}</td>
<td class="text-end">
<div class="actions">
<a href="javascript:;" class="btn btn-sm bg-success-light me-2">
<i class="feather-eye"></i>
</a>
<a href="{{ url('teacher/edit/'.$list->id) }}" class="btn btn-sm bg-danger-light">
<i class="feather-edit"></i>
</a>
<a class="btn btn-sm bg-danger-light teacher_delete" data-bs-toggle="modal" data-bs-target="#teacherDelete">
<i class="feather-trash-2 me-1"></i>
</a>
</div>
</td>
</tr>
@endforeach

</tbody>
</table>
</div>
Expand All @@ -132,8 +133,44 @@ class="fas fa-download"></i> Download</a>
</div>
</div>

@section('script')
{{-- model teacher delete --}}
<div class="modal fade contentmodal" id="teacherDelete" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content doctor-profile">
<div class="modal-header pb-0 border-bottom-0 justify-content-end">
<button type="button" class="close-btn" data-bs-dismiss="modal" aria-label="Close"><i
class="feather-x-circle"></i>
</button>
</div>
<div class="modal-body">
<form action="{{ route('teacher/delete') }}" method="POST">
@csrf
<div class="delete-wrap text-center">
<div class="del-icon">
<i class="feather-x-circle"></i>
</div>
<input type="hidden" name="id" class="e_id" value="">
<h2>Sure you want to delete</h2>
<div class="submit-section">
<button type="submit" class="btn btn-success me-2">Yes</button>
<a class="btn btn-danger" data-bs-dismiss="modal">No</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>

@section('script')
{{-- delete js --}}
<script>
$(document).on('click','.teacher_delete',function()
{
var _this = $(this).parents('tr');
$('.e_id').val(_this.find('.id').text());
});
</script>
@endsection

@endsection
3 changes: 1 addition & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,5 @@ function set_active( $route ) {
Route::post('teacher/save', 'saveRecord')->middleware('auth')->name('teacher/save'); // save record
Route::get('teacher/edit/{id}', 'editRecord'); // view teacher record
Route::post('teacher/update', 'updateRecordTeacher')->middleware('auth')->name('teacher/update'); // update record


Route::post('teacher/delete', 'teacherDelete')->name('teacher/delete'); // delete record teacher
});

0 comments on commit c412cf0

Please sign in to comment.