/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $user = Auth::user();
     $email = $user->email;
     $array['pors'] = por::where('email', $email)->get();
     foreach ($array['pors'] as $arr) {
         if ($arr['Position'] != 'Core' && $arr['Position'] != 'Panel') {
             unset($arr);
         } else {
             $array0['porrequests'] = porrequests::where('Department', $arr['Department'])->get();
             foreach ($array0['porrequests'] as $arr0) {
                 if ($arr['Position'] == $arr0['ApproverPosition'] && $arr['Organisation'] == $arr0['Organisation']) {
                     $str = "@\$#" . $arr['Position'] . "@\$#" . $arr['Organisation'];
                     $str1 = "@\$#" . $arr0['id'] . "@\$#" . $arr0['RequestEmail'];
                     $arr1['pors'][$str][$str1] = '1';
                 }
             }
         }
     }
     if (isset($arr1['pors'])) {
         return view('requests', $arr1);
     } else {
         $str = "No Core or Panel positions are registered for.";
         $arr['pors'][$str] = "Nil";
         return view('requests' . $arr);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $user = Auth::user();
     $json = json_decode(Storage::get('Categories.json'), true);
     $position = $request->input('SePosition');
     if (!empty($request->input('Position'))) {
         $position = $request->input('Position');
         $position = htmlspecialchars($position);
         $json['PORPosition'][$position] = $position;
     }
     $SubDepartment = $request->input('SeSubDepartment');
     if (!empty($request->input('SubDepartment'))) {
         $SubDepartment = $request->input('SubDepartment');
         $SubDepartment = htmlspecialchars($SubDepartment);
         $json['PORSubDepartment'][$SubDepartment] = $SubDepartment;
     }
     $Department = $request->input('SeDepartment');
     if (!empty($request->input('Department'))) {
         $Department = $request->input('Department');
         $Department = htmlspecialchars($Department);
         $json['PORDepartment'][$Department] = $Department;
     }
     $Organisation = $request->input('SeOrganisation');
     if (!empty($request->input('Organisation'))) {
         $Organisation = $request->input('Organisation');
         $Organisation = htmlspecialchars($Organisation);
         $json['Organisation'][$Organisation] = $Organisation;
     }
     Storage::put('categories.json', json_encode($json));
     $email = $user->email;
     $POR = new por();
     $POR->email = $email;
     $POR->Position = $position;
     $POR->SubDepartment = $SubDepartment;
     $POR->Department = $Department;
     $POR->Organisation = $Organisation;
     $POR->Status = 0;
     $POR->save();
     $Request = new porrequests();
     $Request->RequestEmail = $email;
     $Request->RequestPosition = $position;
     if ($position == 'Core') {
         $Request->ApproverPosition = 'Panel';
     } else {
         $Request->ApproverPosition = 'Core';
     }
     $Request->SubDepartment = $SubDepartment;
     $Request->Department = $Department;
     $Request->Organisation = $Organisation;
     $Request->save();
     $Msg['Msg'] = "Your request has been sent for approval";
     return view('addPOR', $Msg);
 }