public function remove($id)
 {
     $license = License::findOrFail($id);
     $date = new \DateTime();
     //this returns the current date time
     $license->user_id = 0;
     $license->save();
     if ($license->user_id != 0) {
         DB::table('users')->where('id', $license->user_id)->update(array('status' => 'INACTIVE', 'inactive_date' => $date));
     }
     \Session::flash('message', 'You have successfully remove user for this License');
     $company = Company::findOrFail($license->company_id);
     $licenses = License::whereRaw('company_id like ? order by id', array($license->company_id))->paginate(15)->appends(Input::except('page'));
     return view('licenses.list', compact('company', 'licenses'));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Requests\CreateUserRequest $request, User $user)
 {
     $license = License::whereRaw('company_id = ? and status = "ACTIVE" and user_id = 0', array(Auth::user()->company_id))->first();
     if (!isset($license->id)) {
         \Session::flash('message', 'You have not Licenses');
         return Redirect::action('CompanyUserController@index');
     }
     $password = $request->password;
     $user = new User();
     $request->offsetSet('password', bcrypt($request->password));
     $request->offsetSet('created_by', Auth::user()->id);
     $request->offsetSet('updated_by', Auth::user()->id);
     $request->offsetSet('status', "NEW");
     if ($request->role_id != 2) {
         $request->offsetSet('manager_id', 0);
     }
     if (Auth::user()->role->id == 3) {
         $request->offsetSet('manager_id', Auth::user()->id);
     }
     $user->create($request->all());
     $user = DB::table('users')->where('email', $request->email)->first();
     $userPassword = new UserPassword();
     $userPassword->user_id = $user->id;
     $userPassword->crypt_password = \Crypt::encrypt($password);
     $userPassword->updated_at = new \DateTime();
     $userPassword->created_at = new \DateTime();
     $userPassword->save();
     $goal = parent::assembleGoalSetting();
     $goal->user_id = $user->id;
     $goal->created_by = Auth::user()->id;
     $goal->updated_by = Auth::user()->id;
     $goal->save();
     $license->user_id = $user->id;
     $license->update();
     $contactEmail = $user->email;
     Mail::send('emails.hello', array('first_name' => $user->first_name, 'user_name' => $user->email, 'password' => $password), function ($message) use($contactEmail) {
         $message->from('*****@*****.**', 'Sales Performance Indicator');
         $message->to($contactEmail, 'Sales Performance Indicator')->subject('Welcome to Sales Performance Indicator!');
     });
     \Session::flash('message', 'You have successfully created ' . $user->last_name . ', ' . $user->first_name);
     return Redirect::action('CompanyUserController@index');
 }