`i want to create a page that mark attendence of student in that page i just select any student name and in the other dropdowns its semester and batch and degree should auo selected
**
this is my code for blade view is there any error in the balde view **
@csrf
<select class="form-control mb-4" id="studentSelect">
<option value="">Select Student</option>
@foreach ($students as $student)
<option value="{{ $student->Student_id }}">{{ $student->Name }}</option>
@endforeach
</select>
<select name="batch_id"class="form-control mb-4" required>
<option value="" selected disabled>-- Select Batch --</option>
<option value="" id="batch"></option>
</select>
<select name="semester_id" class="form-control mb-4" required>
<option value="" selected disabled>-- Select Semester --</option>
<option value="" id="semester"></option>
</select>
<select name="degree_id" class="form-control mb-4" required>
<option value="" selected disabled>-- Select Degree --</option>
<option value="" id="degree"></option>
</select>
</form>
<script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4="
crossorigin="anonymous"></script>
<script>
$('#studentSelect').on('change', function() {
var studentId = $(this).val();
$.ajax({
type: 'POST',
url: '/getStudentDetails',
data: {
'_token': '{{ csrf_token() }}',
'Student_id': studentId
},
success: function(data) {
$('#semester').val(data.semester);
$('#batch').val(data.batch);
$('#degree').val(data.degree);
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
// Handle the error appropriately, e.g., display an error message
}
});
});
</script>
and this is the controller Code for attendece
<?php
namespace AppHttpControllers;
use AppModelsbatch;
use AppModelsdegrees;
use AppModelssemester;
use AppModelsstudents;
use IlluminateHttpRequest;
use IlluminateSupportFacadesDB;
use IlluminateSupportFacadesSession;
class attendanceController extends Controller
{
function showAttendencePage() {
if(Session::has('user')){
$students = students::all();
return view('Pages.facuilty.markAttendence',['students'=>$students]);
}else{
return view('index');
}
}
public function getStudentDetails(Request $request)
{ $student = students::find($request->Student_id);
if ($student) {
return response()->json([
'semester' => $student->Semester_id,
'batch' => $student->Batch_id,
'degree' => $student->Degree_id,
]);
}
return response()->json(['error' => 'Student not found']);
}
}
*
*and this is the web routes **
Route::group(['middleware' => ['web']], function () {
Route::get('/mark/attendence/student',[attendanceController::class,'showAttendencePage'])->name('showAttendencePage');
Route::post('/getStudentDetails', [attendanceController::class,'getStudentDetails'])->name('getStudentDetails');
});
so that is my code and tell me if any error is or any mistake that i can’t solve so please tell me
2
Answers