student.php
model
migration
COntroller
public function destroy(Request $request, $id)
{
$student = Student::find($id);
if ($student) {
$student->delete();
return redirect()->back()->with('success', 'Student soft deleted successfully.');
}
return redirect()->back()->with('error', 'Student not found.');
}
html
need the query results with softdelete
$models = YourModel::withTrashed()->get();
restore a soft deleted record
$model = YourModel::withTrashed()->find($id);
$model->restore();
To restore a soft deleted record, you can use the restore
method. Here's an example
$model = YourModel::withTrashed()->find($id);
$model->restore();
f you want to force delete a soft deleted record, removing it permanently from the table, you can use the forceDelete
method. Here's an example:
$model = YourModel::withTrashed()->find($id); $model->forceDelete();
No comments:
Post a Comment