IMMREX7

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

<?php

namespace App\Http\Controllers\School\Hostel;

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

class HosteliteController extends SchoolController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request) {
        $classes = \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        $students = DB::table('hostel_students')
                ->join('hostel_floors','hostel_students.idFloor','=','hostel_floors.idFloor')
                ->join('hostel_rooms','hostel_students.idRoom','=','hostel_rooms.idRoom')
                ->join('hostel_beds','hostel_students.idBed','=','hostel_beds.idBed')
                ->join('students','hostel_students.idStudent','=','students.idStudent')
                ->join('classes', 'students.idClass', '=', 'classes.idClass')
                ->join('sections', 'students.idSection', '=', 'sections.idSection')
                ->where('hostel_students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->select('ecNo','hostel_students.idFinancialYear', 'firstName', 'lastName', 'middleName','floorName','bedName','roomName','father_fname', 'father_lname', 'father_mobile', 'className', 'sectionName');
        if ($request->has('classes') && count($request->classes) > 0) {
            $students = $students->whereIn('students.idClass', $request->classes)
                    ->where('hostel_students.idFinancialYear','=', $request->idFinancialYear)
                    ->get();
        } else if ($request->has('sections') && count($request->sections) > 0) {
            $students = $students->whereIn('students.idSection', $request->sections)
                    ->where('hostel_students.idFinancialYear','=', $request->idFinancialYear)
                    ->get();
        } else if ($request->has('students') && count($request->students) > 0) {
            $students = $students->whereIn('students.idStudent', $request->students)
                    ->where('hostel_students.idFinancialYear','=', $request->idFinancialYear)
                    ->get();
        } else {
            $students = $students->where('hostel_students.idFinancialYear','=', Session::get('idFinancialYear'))->get();
        }
        return view('schools.hostel.hostelites', compact('classes', 'students', 'floors'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request) {
        $floors = ['' => '---Select Floor---'] + \App\HostelFloor::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->get()->pluck('floorName', 'idFloor')->toArray();
        $classes = \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        
        $hostel_students = \App\Hostelite::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->pluck('idStudent')->toArray();
            
        $students = DB::table('students')
                ->join('classes', 'students.idClass', '=', 'classes.idClass')
                ->join('sections', 'students.idSection', '=', 'sections.idSection')
                ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                 ->where('students.idFinancialYear','=', Session::get('idFinancialYear'))
                ->whereNotIn('students.idStudent',$hostel_students)
                ->select('ecNo', 'firstName', 'lastName', 'middleName', 'father_fname', 'father_lname', 'father_mobile', 'className', 'sectionName', 'idStudent');
        if ($request->has('classes') && count($request->classes) > 0) {
            $students = $students->whereIn('students.idClass', $request->classes)->get();
        } else if ($request->has('sections') && count($request->sections) > 0) {
            $students = $students->whereIn('students.idSection', $request->sections)
                    ->get();
        } else if ($request->has('students') && count($request->students) > 0) {
            $students = $students->whereIn('idStudent', $request->students)
                    ->get();
        } else {
            $students = [];
        }
        return view('schools.hostel.add_hostelite', compact('classes', 'students', 'floors'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request) {
        //dd($request->all());
        $rules = [];
        if ($request->has('students') && $request->students != null) {
            foreach ($request->students as $key => $var) {
                if (($var['idFloor'] != null) && ($var['idRoom'] != null) && ($var['idBed'] != null)) {
                    
                }
            }
        } else {
            $rules += ['student' => 'required'];
        }
        $messages = ['student.required' => 'Atleast One student must be selected'];
        $this->validate($request, $rules, $messages);
        foreach ($request->students as $key => $var) {
            if (($var['idFloor'] != null) && ($var['idRoom'] != null) && ($var['idBed'] != null)) {
                $hostelite = new \App\Hostelite();
                $hostelite->fill($request->all());
                $hostelite->idSchool = Auth::guard('school')->user()->idSchool;
                $hostelite->idFinancialYear = Session::get('idFinancialYear');
                $hostelite->idStudent = $key;
                $hostelite->idFloor = $var['idFloor'];
                $hostelite->idRoom = $var['idRoom'];
                $hostelite->idBed = $var['idBed'];
                $hostelite->save();
            }
        }
        flash('Hostel has been assigned to Student.');
        return redirect('school/hostelites');
    }

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

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id) {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id) {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id) {
        //
    }

    public function getHostelite($id) {
        $students = DB::table('hostel_students')
                ->join('students','hostel_students.idStudent','=','students.idStudent')
                ->where('idSection','=',$id)
                ->select(DB::raw("CONCAT(firstName,' ',lastName,'(',ecNo,')') AS name"),'hostel_students.idStudent')
                ->pluck('name','idStudent')->toArray();
        return json_encode($students);
    }
}

Copyright © 2021 - 2025 IMMREX7