/**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update($user_name, Requests\User\UpdateRequest $request)
 {
     $user = \Nexus\User::where('username', $user_name)->firstOrFail();
     $input = $request->all();
     if ($input['password'] != '') {
         // to prevent setting password to an empty string https://trello.com/c/y1WAxwfb
         $input['password'] = \Hash::make($input['password']);
     } else {
         unset($input['password']);
     }
     $user->update($input);
     \Nexus\Helpers\FlashHelper::showAlert('Profile Updated!', 'success');
     return redirect('/users/' . $user_name);
 }
    /**
     * redirects a visitor to a section  with an updated topic
     */
    public function leap()
    {
        // should we be passing the user_id into this method?
        $views = \Nexus\View::with('topic')->where('user_id', \Auth::user()->id)->where('latest_view_date', '!=', "0000-00-00 00:00:00")->where('unsubscribed', 0)->get();
        $topics = $views->map(function ($view, $key) {
            if (!is_null($view->topic)) {
                if ($view->latest_view_date != $view->topic->most_recent_post_time) {
                    return $view;
                }
            }
        })->reject(function ($view) {
            return empty($view);
        });
        if ($topics->count()) {
            $destinationTopic = $topics->first()->topic;
            // set alert
            $topicURL = action('Nexus\\TopicController@show', ['topic_id' => $destinationTopic->id]);
            // force the url to be relative so we don't later make this open in the new window
            $topicURL = str_replace(url('/'), '', $topicURL);
            $topicTitle = $destinationTopic->title;
            $subscribeAllURL = action('Nexus\\TopicController@markAllSubscribedTopicsAsRead');
            $subscribeAllURL = str_replace(url('/'), '', $subscribeAllURL);
            $message = <<<Markdown
People have been talking! New posts found in **[{$topicTitle}]({$topicURL})**

Seeing too many old topics then **[mark all subscribed topics as read]({$subscribeAllURL})**
Markdown;
            \Nexus\Helpers\FlashHelper::showAlert($message, 'success');
            // redirect to the parent section of the unread topic
            return redirect()->action('Nexus\\SectionController@show', [$destinationTopic->section->id]);
        } else {
            // set alert
            $message = 'No updated topics found. Why not start a new conversation or read more sections?';
            \Nexus\Helpers\FlashHelper::showAlert($message, 'warning');
            // redirect to main menu
            return redirect('/');
        }
    }
 public function markAllSubscribedTopicsAsRead()
 {
     \Nexus\Helpers\ViewHelper::catchUpCatchUp(\Auth::user());
     $message = '**Success!** all subscribed topics are now marked as read';
     \Nexus\Helpers\FlashHelper::showAlert($message, 'success');
     return redirect('/');
 }