validate([ 'first_name' => 'required|string|max:255', 'last_name' => 'required|string|max:255', 'nic' => 'nullable|string|max:50', 'nationality' => 'nullable|string|max:100', 'address' => 'required|string|max:500', 'state' => 'required|string|max:255', 'gender' => 'nullable|string', 'dob' => 'nullable|date', 'mobile' => 'required|string|max:20', 'mobile2' => 'nullable|string|max:20', 'email' => 'required|email|max:255', 'preferred_contact_method' => 'nullable|string', 'still_at_school' => 'nullable|string', 'highest_qualification' => 'nullable|string', 'school_name' => 'nullable|string|max:255', 'year_completed' => 'nullable|numeric|digits:4', 'exam_passed' => 'nullable|string', 'subjects' => 'nullable|string|max:255', 'grades_results' => 'nullable|string', 'certificates.*' => 'nullable|file|mimes:pdf,jpg,jpeg,png|max:5120', // Max 5MB per file 'emergency_contact_name' => 'required|string|max:255', 'emergency_contact_relationship' => 'required|string|max:255', ]); // 2. Multi File Upload Process $certificatePaths = []; if ($request->hasFile('certificates')) { foreach ($request->file('certificates') as $file) { $path = $file->store('certificates', 'public'); $certificatePaths[] = $path; } } // 3. Current Logged-in User ID එක set කිරීම & Data Save කිරීම $application = new Application($validatedData); $application->user_id = Auth::id(); // Log unukena ge ID eka attach wei $application->certificates = $certificatePaths; // Paths array eka save wei $application->save(); return redirect()->back()->with('success', 'Your application has been submitted successfully!'); } }