/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $rules = ['name' => ['required', 'unique:archive,name', 'regex:' . config('app.expressions.dir')]];
     if ($this->systemAdmin) {
         $rules['department_id'] = 'required';
     }
     $validator = Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     DB::transaction(function () use($request) {
         #add all papers from department to archive
         $archive = Archive::create($request->all());
         $department = Department::findOrFail($request->get('department_id'));
         $paperObj = new PaperClass();
         $archivePath = 'archive/';
         if (!File::exists($archivePath . $archive->name)) {
             File::makeDirectory($archivePath . $archive->name);
         }
         $newPath = $archivePath . $archive->name . '/';
         $oldPath = $paperObj->prefix() . '/' . $department->keyword . '/';
         foreach ($department->papers()->archived()->get() as $paper) {
             $paper->archive()->associate($archive);
             $paper->save();
             File::move($oldPath . $paper->source, $newPath . $paper->source);
             if ($paper->payment_source) {
                 File::move($oldPath . $paper->payment_source, $newPath . $paper->payment_source);
             }
         }
     });
     return redirect()->action('Admin\\ArchiveController@index')->with('success', 'updated');
 }
 public function adminEmailUsr(Request $requests, $user_id)
 {
     $user_email = Input::get('email');
     if (UserMod::where('id', $user_id)->where('role', '=', 'Administrator')->exists() and UserMod::where('email', $user_email)->exists()) {
         // This is where system stores "Archive" of mails been sent from Admin to any person
         Archive::create(array('email_subject' => Input::get('subject'), 'rec_name' => Input::get('getterName'), 'rec_email' => Input::get('email'), 'message' => Input::get('message')));
         // This is where system generates e-mail from information taking from "form"
         $contactName = Input::get('getterName');
         $contactEmail = Input::get('email');
         $contactMessage = Input::get('message');
         $messageSubject = Input::get('subject');
         $admin = UserMod::where('id', $user_id)->where('role', '=', 'Administrator')->first();
         $data = array('name' => $contactName, 'Recemail' => $contactEmail, 'Emessage' => $contactMessage, 'sender' => $admin->name);
         Mail::send('emailUsr', $data, function ($message) use($contactEmail, $contactName, $messageSubject) {
             $message->to($contactEmail, $contactName)->subject($messageSubject);
         });
         Session::flash('user_email_success', "");
         return back()->withInput();
     } else {
         Session::flash('failed', "Something went wrong, please try again!");
         return back()->withInput();
     }
 }