IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/Student/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/Student/StudentController.php

<?php

namespace App\Http\Controllers\Student;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
use DB;
use Session;

class StudentController extends Controller {

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    protected $redirectTo = '/student';

    public function __construct() {
        $this->middleware('auth:student');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function dashboard(Request $request) {
//        $students = \App\AdmEntry::where('father_mobile', '=', Auth::guard('student')->user()->mobile)
//                ->whereOr('mother_mobile', '=', Auth::guard('student')->user()->mobile)
//                ->get();
//        if (count($students) > 1) {
//            return view('students.dashboard', compact('students'));
//        } else {
//            $students = [];
//            $student = \App\AdmEntry::where('father_mobile', '=', Auth::guard('student')->user()->mobile)
//                    ->whereOr('mother_mobile', '=', Auth::guard('student')->user()->mobile)
//                    ->first();
//            Session::put('idStudent', $student->idStudent);
//            return view('students.dashboard', compact('students'));
        if(Session::get('idStudent') == null){
            Auth::guard('student')->logout();

            //$request->session()->invalidate();
            $request->session()->flush();
            $request->session()->regenerate();
            //  return redirect('/farmer/login');
            return redirect('student/login');
        }
        $student = \App\AdmEntry::
                //where('father_mobile', '=', Auth::guard('student')->user()->mobile)
               // ->orWhere('mother_mobile', '=', Auth::guard('student')->user()->mobile)
                where('idStudent', '=', Session::get('idStudent'))
                ->first();
                
                $school = \App\School::where('idSchool','=',$student->idSchool)->first();
                if($school == null){

                    $students = \App\AdmEntry::where('father_mobile', '=', Auth::guard('student')->user()->mobile)
                        ->orWhere('mother_mobile', '=', Auth::guard('student')->user()->mobile)
                        ->select('idStudent','idSchool')
                        ->get();
                    $studentFound = 0;
                    foreach($students as $bros){
                        $school = \App\School::where('idSchool','=',$bros->idSchool)->first();
                        if($school != null) {
                            Session::put('idStudent',$bros->idStudent);
                            $studentFound++;
                            break;
                        }
                    }

                    if($studentFound == 0){
                        Auth::guard('student')->logout();
        
                        //$request->session()->invalidate();
                        $request->session()->flush();
                        $request->session()->regenerate();
                        //  return redirect('/farmer/login');
                        return redirect('student/login');
                    }
                   
                }
        $student = \App\AdmEntry::
                //where('father_mobile', '=', Auth::guard('student')->user()->mobile)
               // ->orWhere('mother_mobile', '=', Auth::guard('student')->user()->mobile)
                where('idStudent', '=', Session::get('idStudent'))
                ->first();        
        $periods = \App\Period::where('idSchool', '=', $student->idSchool)
                        ->where('idClass', '=', $student->idClass)
                        ->where('idSection', '=', $student->idSection)->get();
        $holidays = \App\Holiday::where('idSchool', '=', $student->idSchool)->get();
        return view('students.dashboard', compact('student', 'periods', 'holidays'));
    }

    public function goToDashboard($id) {
        $student = \App\AdmEntry::where('idStudent', '=', $id)->first();
        session()->forget('idStudent');
        Session::save();
        session()->put('idStudent', $student->idStudent);
        return redirect('student');
    }

    public function switchProfile() {
        //removed the financialYear where clause
       $students = \App\AdmEntry::where('father_mobile', '=', Auth::guard('student')->user()->mobile)
                ->orWhere('mother_mobile', '=', Auth::guard('student')->user()->mobile)
                ->where('idStudent', '!=', Session::get('idStudent'))
                ->get();
        return view('students.switchdashboard', compact('students'));
    }

}

Copyright © 2021 - 2025 IMMREX7