public function excel() { $registration = Registration::all(); Excel::create('Registrations', function ($excel) use($registration) { $excel->sheet('List of Registrants', function ($sheet) use($registration) { $sheet->fromModel($registration, null, 'A1', false, false); $sheet->prependRow(1, array('ID', 'Reg_ID', 'Name', 'Gender', 'Degree', 'Course', 'Year', 'Department', 'College with Address', 'Email ID', 'Contanct No.', 'Guardian\'s contanct No.', 'Amount', 'DD No.', 'DD Date', 'Bank Name', 'Reason', 'is NITT', 'Email Sent')); $sheet->freezePane('C2'); $sheet->getColumnDimension('A')->setVisible(false); $sheet->getColumnDimension('R')->setVisible(false); $sheet->getColumnDimension('S')->setVisible(false); }); })->export('xlsx'); }
public function store_registration(Request $request) { $messages = ['digits_between' => 'The :attribute must be 10 digits.']; $v = Validator::make($request->all(), ['name' => 'required|min:3|max:255', 'gender' => 'required|in:male,female', 'degree' => 'required|in:UG,PG', 'course' => 'required|in:B.E,B.Tech,B.Sc,B.Com,B.A,M.Tech,M.B.A,M.Sc,other', 'other_course' => 'required_if:course,other', 'year' => 'required|in:Final year U.G.,Final year P.G.,Pre-final year of Engineering', 'branch' => 'required|min:2|max:20', 'college' => 'required|min:10|max:150', 'email' => 'required|email|unique:registrations', 'phone' => 'required|integer|digits_between:10,10', 'guardian_phone' => 'required|integer|digits_between:10,10', 'dd_no' => 'required|min:5|max:10', 'dd_date' => 'required|min:10|max:30', 'bank_name' => 'required|min:2|max:20', 'reason' => 'required|min:20|max:200'], $messages); //redirect to registration page with errors if there is any if ($v->fails()) { return redirect()->back()->withErrors($v->errors()); } //else if (strcmp($request->course, "other") == 0) { $request->course = $request->other_course; } if (strcmp($request->degree, "UG") == 0) { $amount = 960; } else { $amount = 1560; } $registration = new Registration(); $registration->name = $request->name; $registration->gender = $request->gender; $registration->degree = $request->degree; $registration->course = $request->course; $registration->year = $request->year; $registration->dept = $request->branch; $registration->college_address = $request->college; $registration->email = $request->email; $registration->mobile_no = $request->phone; $registration->guardian_mobile_no = $request->guardian_phone; $registration->amount = $amount; $registration->dd_no = $request->dd_no; $registration->dd_date = $request->dd_date; $registration->bank_name = $request->bank_name; $registration->reason = $request->reason; //save the record to table $save_status = $registration->save(); if (!$save_status) { return redirect('/registration'); } //update the reg_id of the inserted record $registration->reg_id = $registration->id + 1000; $registration->save(); //generating the pdf $path = getcwd(); $im_page_1 = imagecreatefromjpeg($path . '/images/Page1.jpg'); $black = imagecolorallocate($im_page_1, 0, 0, 0); $font = $path . '/font/Helvetica.otf'; $d = strtotime("now"); $today = date("d-m-Y", $d); $college = $registration->college_address; $words = explode(" ", $college); $lines = [""]; $k = 0; foreach ($words as $word) { if (strlen($lines[$k]) + strlen($word) <= 50) { $lines[$k] .= " " . $word; } else { $k++; $lines[$k] = ""; $lines[$k] .= " " . $word; } } $k = 0; foreach ($lines as $line) { imagettftext($im_page_1, 35, 0, 740, 1475 + $k * 50, $black, $font, $line); $k++; } imagettftext($im_page_1, 35, 0, 2000, 1065, $black, $font, $registration->reg_id); imagettftext($im_page_1, 35, 0, 750, 1325, $black, $font, $registration->name); imagettftext($im_page_1, 35, 0, 750, 1625, $black, $font, $registration->degree); imagettftext($im_page_1, 35, 0, 750, 1775, $black, $font, $registration->course); imagettftext($im_page_1, 35, 0, 540, 2175, $black, $font, $today); $filename_page_1 = $registration->reg_id . ".png"; imagepng($im_page_1, $filename_page_1); $pdf = new Imagick(array($filename_page_1)); $pdf->setImageFormat("pdf"); $filename_pdf = $registration->reg_id . '.pdf'; if (!$pdf->writeImages($filename_pdf, true)) { die('Could not write!'); } header('Content-Type: application/pdf'); header("Content-Disposition: inline; filename=" . $filename_pdf); @readfile($filename_pdf); $delete_status_page_1 = unlink($filename_page_1); $delete_status_pdf = unlink($filename_pdf); }
public function show_registration(Request $request) { $id = $request->get('id'); $registration = Registration::find($id); echo json_encode($registration); }