#Inserting data according to the checked on checkbox

9 messages · Page 1 of 1 (latest)

orchid vapor
#

how can I insert this data according to the row that are checked I have no idea how to do that can anyone help >

shadow island
#

@orchid vapor What have you tried so far?

orchid vapor
shadow island
#

Try yourself first, then come back when you’re actually stuck, and not just because you haven’t bothered to attempt it.

orchid vapor
#
// web.php

Route::get('/enroll', [DepartmentController::class, 'showEnrollForm'])->name('enroll');
Route::post('/enroll', [DepartmentController::class, 'submitEnrollForm'])->name('enroll.submit');
#
//controller 
public function submitEnrollForm(Request $request)
        {
            // Retrieve the form data
            $sessionId = $request->input('session');
            $sectionId = $request->input('section');
            $courseType = $request->input('course_type');
            
            // Retrieve the department name from the selected course
            $courseId = $request->input('course');
            $course = DB::table('courses')->where('id', $courseId)->first();
        // Retrieve the department name from the selected course
        $course = DB::table('courses')->where('id', $courseId)->first();
        if($course != null) {
            $deptName = $course->department_name;

            // Insert the data into the database
            DB::table('enrolls')->insert([
                'session_name' => $sessionId,
                'section_name' => $sectionId,
                'course_type' => $courseType,
                'dept_name' => $deptName,
            ]);

            // Redirect the user to a success page
            return redirect()->route('enrollment.success');
        } else {
            // Handle the case where the course is not found
            return redirect()->back()->with('error', 'Course not found.');
        }
}

#

page just refreshing after clicking on button data is not inserting