IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/School/Exam/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/School/Exam/ExamReportController.php

<?php

namespace App\Http\Controllers\School\Exam;

use Illuminate\Http\Request;
use App\Http\Controllers\School\SchoolController;
use DB;
use Auth;
use PDF;

class ExamReportController extends SchoolController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index() {   
        $reports = \App\ExamResult::join('exam_types', 'exam_results.idExamType', '=', 'exam_types.idExamType')
            ->select('exam_results.*', 'exam_types.typeName')
            ->where('exam_results.idSchool', '=', Auth::guard('school')->user()->idSchool)->orderBy('exam_results.idResult')->get();

        return view('schools.exams.exam_report', compact('reports'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create() {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request) {

        $pdf = new \LynX39\LaraPdfMerger\PdfManage;
        $examName = "temp";

        if (count($request->idResult) > 0) {
            foreach ($request->idResult as $key => $value) {
                $template = \App\ExamResult::join('exam_types', 'exam_results.idExamType', '=', 'exam_types.idExamType')
                ->select('exam_results.*', 'exam_types.typeName')
                ->where('exam_results.idResult', '=', $value)->first();

                $path = storage_path('app/public/schools/' . $template->idSchool . '/results/' . $template->typeName .'/'. $template->ecNo .'.pdf');
                $pdf->addPDF($path);
                $examName = $template->typeName;
           }

           $path = storage_path('app/public/schools/' . Auth::guard('school')->user()->idSchool . '/results/' . $examName .'/created.pdf');
           $pdf->merge('file',$path, 'P');
           if( $request->download == 'DOWNLOAD SELECTED')
                return response()->download($path);
            else
                return response()->file($path);

        }

        $reports = \App\ExamResult::join('exam_types', 'exam_results.idExamType', '=', 'exam_types.idExamType')
            ->select('exam_results.*', 'exam_types.typeName')
            ->where('exam_results.idSchool', '=', Auth::guard('school')->user()->idSchool)->orderBy('exam_results.idResult')->get();

        return view('schools.exams.exam_report', compact('reports'));
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id) {
        //

    }

    public function viewResult($id){
        $template = \App\ExamResult::join('exam_types', 'exam_results.idExamType', '=', 'exam_types.idExamType')
            ->select('exam_results.*', 'exam_types.typeName')
            ->where('exam_results.idResult', '=', $id)->first();

        $path = storage_path('app/public/schools/' . $template->idSchool . '/results/' . $template->typeName .'/'. $template->ecNo .'.pdf');
        return response()->file($path);
    }

    public function downloadResult($id){
       $template = \App\ExamResult::join('exam_types', 'exam_results.idExamType', '=', 'exam_types.idExamType')
            ->select('exam_results.*', 'exam_types.typeName')
            ->where('exam_results.idResult', '=', $id)->first();

        $path = storage_path('app/public/schools/' . $template->idSchool . '/results/' . $template->typeName .'/'. $template->ecNo .'.pdf');
        return response()->download($path);
    }

}

Copyright © 2021 - 2025 IMMREX7