public function store()
 {
     $redirectID;
     $input = Request::all();
     if (Request::has('created')) {
         $redirectID = $input['id'];
         BusinessPlan::create($input);
     }
     if (Request::has('bpid')) {
         if ($input['bp'] == 'False') {
             $input['bp'] = True;
         } else {
             $input['bp'] = False;
         }
         $input['group'] += 1;
         Goal::create($input);
         $redirectID = $input['bpid'];
     }
     if (Request::has('goal_id')) {
         // return  $input['goal_id'];
         $goals = DB::select("select * from goals where bpid = '" . $input['idbp'] . "'");
         $input['goal_id'] = $goals[$input['goal_id']]->id;
         $objectiveIdent = count(DB::table('objectives')->where('goal_id', $input['goal_id'])->get()) + 1;
         $goalIdent = $input['goal_id'];
         $input['ident'] = "{$goalIdent}.{$objectiveIdent}";
         $redirectIDArray = DB::table('goals')->where('id', $input['goal_id'])->pluck('bpid');
         $redirectID = $redirectIDArray[0];
         Objective::create($input);
     }
     if (Request::has('objective_id')) {
         $input['group'] += 1;
         $objectives = DB::select("select distinct * from goals, objectives where bpid = '" . $input['idbp'] . "' and objectives.goal_id = goals.id");
         $input['objective_id'] = $objectives[$input['objective_id']]->id;
         $input['userId'] += 1;
         $objectiveIdent = DB::table('objectives')->where('id', $input['objective_id'])->pluck('ident');
         $actionIdent = count(DB::table('actions')->where('objective_id', $input['objective_id'])->get()) + 1;
         $input['ident'] = "{$objectiveIdent['0']}.{$actionIdent}";
         $var2 = $input['idbp'];
         $redirectIDArray = DB::table('goals as g')->join('objectives as o', function ($join) use($var2) {
             $join->on('o.goal_id', '=', 'g.id')->where('g.bpid', '=', $var2);
         })->distinct()->pluck('g.bpid');
         $redirectID = $redirectIDArray[0];
         $collabs = "";
         if (array_key_exists('collaborators-groups', $input)) {
             foreach ($input['collaborators-groups'] as $x) {
                 $group = Group::find($x);
                 if ($group != null) {
                     $collabs .= Group::find($x)->name;
                     $collabs .= ", ";
                 } else {
                     $collabs .= "";
                 }
             }
         }
         if (array_key_exists('collaborators-users', $input)) {
             foreach ($input['collaborators-users'] as $x) {
                 $user = User::find($x);
                 if ($user != null) {
                     $collabs .= User::find($x)->name;
                     $collabs .= ", ";
                 } else {
                     $collabs .= "";
                 }
             }
         }
         $collabs = rtrim($collabs, ", ");
         $input['collaborators'] = $collabs;
         Action::create($input);
     }
     if (Request::has('action_id')) {
         $input['group'] += 1;
         $actions = DB::select("select distinct * from goals, objectives,actions where bpid = '" . $input['idbp'] . "' and objectives.goal_id = goals.id and actions.objective_id = objectives.id");
         $input['action_id'] = $actions[$input['action_id']]->id;
         $input['userId'] += 1;
         $actionIdent = DB::table('actions')->where('id', $input['action_id'])->pluck('ident');
         $taskIdent = count(DB::table('tasks')->where('action_id', $input['action_id'])->get()) + 1;
         $input['ident'] = "{$actionIdent['0']}.{$taskIdent}";
         $var2 = $input['idbp'];
         $redirectIDArray = DB::table('goals as g')->join('objectives as o', function ($join2) use($var2) {
             $join2->on('o.goal_id', '=', 'g.id')->where('g.bpid', '=', $var2);
         })->join('actions as a', function ($join) {
             $join->on('a.objective_id', '=', 'o.id');
         })->distinct()->pluck('g.bpid');
         $redirectID = $redirectIDArray[0];
         $collabs = "";
         if (array_key_exists('collaborators-groups', $input)) {
             foreach ($input['collaborators-groups'] as $x) {
                 $group = Group::find($x);
                 if ($group != null) {
                     $collabs .= Group::find($x)->name;
                     $collabs .= ", ";
                 } else {
                     $collabs .= "";
                 }
             }
         }
         if (array_key_exists('collaborators-users', $input)) {
             foreach ($input['collaborators-users'] as $x) {
                 $user = User::find($x);
                 if ($user != null) {
                     $collabs .= User::find($x)->name;
                     $collabs .= ", ";
                 } else {
                     $collabs .= "";
                 }
             }
         }
         $collabs = rtrim($collabs, ", ");
         $input['collaborators'] = $collabs;
         Task::create($input);
     }
     return redirect("businessplan/" . $redirectID . "");
 }