/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //Get all reports where type = cucm_daily
     $reports = Report::where('type', 'cucm_daily')->get();
     //Get all configured CUCM clusters
     $clusters = $this->cluster->all();
     //Set timestamp for file names
     $timeStamp = Carbon::now('America/New_York')->toDateTimeString();
     //Create array to track attachments
     $attachments = [];
     //Loop reports
     foreach ($reports as $index => $report) {
         $attachments[$index] = $report->path . $report->name . '-' . $timeStamp . '.csv';
         //Persist report to disk
         Storage::put($attachments[$index], $report->csv_headers);
         //Loop each cluster and run the reports
         foreach ($clusters as $cluster) {
             $this->dispatch(new $report->job($cluster, $attachments[$index]));
         }
     }
     //Reports are done running, let's email to results
     $beautymail = app()->make(\Snowfire\Beautymail\Beautymail::class);
     $beautymail->send('emails.cucmDailyReporting', [], function ($message) use($attachments) {
         //TODO: Create system for users to manage report subscriptions.
         $message->to(['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'])->subject('CUCM Daily Report');
         //Add all reports to email
         foreach ($attachments as $report) {
             $message->attach(storage_path($report));
         }
     });
 }
 /**
  * @param CreateUserRequest $request
  *
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function store(CreateUserRequest $request)
 {
     $attributes = $request->all();
     Audit::log(Auth::user()->id, trans('admin/users/general.audit-log.category'), trans('admin/users/general.audit-log.msg-store', ['username' => $attributes['username']]));
     if (array_key_exists('selected_roles', $attributes)) {
         $attributes['role'] = explode(",", $attributes['selected_roles']);
     }
     if ($attributes['role'][0] == '') {
         $attributes['role'][0] = "2";
     }
     // Create basic user.
     $user = $this->user->create($attributes);
     // Run the update method to set enabled status and roles membership.
     $user->update($attributes);
     //       TODO: Create front end system to manage users and clusters
     //       TODO: In the meantime, give all users access to every cluster.
     $clusters = Cluster::all();
     foreach ($clusters as $cluster) {
         $user->clusters()->attach($cluster);
     }
     /*
      * Assign the new user's active cluster
      */
     $user->activateCluster($attributes['activeCluster']);
     /*
      * Assign the department
      */
     $department = Department::find($attributes['department']);
     $department->users()->save($user);
     $user->save();
     alert()->success(trans('admin/users/general.status.created'));
     // 'User successfully created');
     return redirect('/admin/users');
 }