format your code properly if you want help
The GET method is not supported for route workshop/mold-identification/save-to-approval. Supported methods: POST.
the case is that I select a row using the checkbox then when I save the selected row is saved to the Approv Mold table. but in console error "500"
look at my codes
web.php Route::get('workshop/mold-identification', [MoldIdentificationController::class, 'index']); Route::get('workshop/mold-identification/edit-mold-identification/{id}', [MoldIdentificationController::class, 'edit']); Route::post('workshop/mold-identification/save-to-approval', [MoldIdentificationController::class, 'saveToApproval'])->name('saveToApproval');
Route::get('workshop/mold-problem', [MoldProblemController::class, 'index']);
index.blade.php
ajax (index.blade.php) $(document).ready(function() { // Initialize DataTable var dataTable = $('moldidentification-table').DataTable({ // Your DataTable configuration });
// Handle "Save" button click event
$('#btnMoveToApprovalMold').on('click', function() {
var selectedRowsData = [];
// Iterate through all rows in the DataTable
dataTable.rows().every(function() {
var data = this.data();
var row = this.node();
// Check if the checkbox in the row is checked
var checkbox = $(row).find('.form-check-input');
if (checkbox.is(':checked')) {
// Push the data of the selected row into the array
selectedRowsData.push(data);
}
});
var csrfToken = $('meta[name="csrf-token"]').attr('content');
$.ajax({
url: "{{ url('workshop/mold-identification/save-to-approval') }}",
type: "POST",
data: {
selectedRows: selectedRowsData,
_token: csrfToken
},
success: function(response) {
swal({
title: 'SUCCEED!',
text: 'Move to save table Approv Mold successfully!',
icon: 'success',
timer: 2000,
showConfirmButton: false,
showCancelButton: false,
buttons: false,
})
},
error: function(error) {
swal({
title: 'FAILED!',
text: 'Failed Move to Save Table Approv Mold!',
icon: 'error',
timer: 2000,
showConfirmButton: false,
showCancelButton: false,
buttons: false,
})
}
});
});
});
MoldIdentificationController.php: public function saveToApproval(Request $request) { $selectedRows = $request->input('selectedRows');
foreach ($selectedRows as $row) {
ApprovMold::create([
'kode_barang' => $row['kode_barang'],
'qty_wo' => $row['qty_wo'],
'uom' => $row['uom'],
'tipe' => $row['tipe'],
'kode_molding' => $row['kode_molding'],
'tonnage' => $row['tonnage'],
'cycle_time' => $row['cycle_time'],
'jenis_material' => $row['jenis_material'],
'no_wo' => $row['no_wo'],
'tgl_wo' => $row['tgl_wo'],
'estimasi_time' => $row['estimasi_time'],
'nama_barang' => $row['nama_barang'],
'is_active' => 'Active',
'created_at' => now(),
'updated_at' => now(),
]);
}
return response()->json(['message' => 'Data saved successfully!']);
}
checkbox datatable: public function dataTable(QueryBuilder $query): EloquentDataTable { return (new EloquentDataTable($query)) ->addColumn('checkbox', function($row){ $checkBox = '';
return $checkBox;
})
}
I see this error in console. POST http://127.0.0.1:8000/workshop/mold-identification/save-to-approval 500 (Internal Server Error)
Please or to participate in this conversation.