Checking if "other" users is logged in/ logged out using Laravel 5

check voter registration status
how can i check my voter history
check voter registration california
can i vote
how to find out if someone is a registered democrat or republican
register to vote
am i registered to vote texas
check voter registration ny

I am creating an application that is similar to a chat application.

I wish to be able to determine if a user is logged in or not.

The way I am doing this is by having a is_logged_in field in the users table.

However I am unsure in how to update this variable, as I don't know what method is called during logout.

I assume it would be something like this:

class AuthController extends Controller
{
    //...
    public function login($user)
    {
        $user->is_logged_in = true;
        $user->save();
    }

    public function logout($user)
    {
        $user->is_logged_in = false;
        $user->save();
    }

    //...
}

Of course the login and logout aren't the methods that run when the user actually logs in and logs out, but I am unsure as to where to put the logic.

Update

These are the routes for authentication.

Route::get('login', 'Auth\AuthController@getLogin')->name('login');
Route::post('login', 'Auth\AuthController@postLogin')->name('postLogin');
Route::get('logout', 'Auth\AuthController@getLogout')->name('logout');

Route::get('register', 'Auth\AuthController@getRegister')->name('register');
Route::post('register', 'Auth\AuthController@postRegister')->name('postRegister');

EDIT I am aware that I can check if current user is authenticated using:

Auth::check()

However, this does not help determine if OTHER users are logged in or not

class AuthController extends Controller
{
   //...
   public function login($user)
   {
      // You can choose to check if the user is logged in
      // before you authenticate the user but its not really necessary because it can cause issues
      if(Auth::check()){
        // user is logged in
      }else{
         if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
           // The user is active, not suspended, and exists.
         }
      }
   }

   public function logout($user)
   {
     if(!Auth::check()){
       // user is logged out
     }else{
       Auth::logout();
     }
   }

}

Edited

I guess you want to know were the authentication really happens(laravel 5.2)

You can check the AuthenticatesUsers Trait. That is were the getLogin() function get called

Check Your Voter Registration Status, It takes less than 30 seconds to check your registration status with our free 50- state tool. And if you're not registered, we'll help you take care of that too. Fast, free� TheAnswerHub is a top destination for finding answers online. Browse our content today! Find check checking account on TheAnswerHub.com.

Solution 1: Edit User Controller [NOT RECOMMENDED]

After some close examination of the AuthicatesUsers trait I managed to fix this issue:

I added the following method to the User Model;

public function authenticated($request, User $user) {
    $user->is_logged_in = true;
    $user->save();
    return redirect()->intended($this->redirectPath());
}

public function getLogout()
{
    if (Auth::check()) {
        $user = Auth::user();
        $user->is_logged_in = false;
        $user->save();
    }

    Auth::logout()
    return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}

Solution 2: Use Events [RECOMMENDED]

I found that Solution 1 is perhaps not the best way, as there are other ways a user can login (e.g. social authentication).

Therefore it is better to use events. i.e. Add these to the EventServiceProvider boot method:

public function boot(DispatcherContract $events)
{
    parent::boot($events);

    $events->listen('auth.login', function (User $user, $remember) {
        $user->is_logged_in = true;
        $user->save();
    });

    $events->listen('auth.logout', function (User $user) {
        $user->is_logged_in = false;
        $user->save();
    });
}

Check if a vehicle is taxed, Check and report if a vehicle has up-to-date vehicle tax or is 'off road' (SORN) Check if a cell has any text in it. To do this task, use the ISTEXT function. Check if a cell matches specific text. Use the IF function to return results for the condition that you specify. Check if part of a cell matches specific text. To do this task, use the IF, SEARCH, and ISNUMBER functions.

If you are trying to create a chat application and you want to know if another user is logged in (or, more specifically, actively available for chats), you are best off using an event based approach using a service like Pusher to identify specific users that are listening on a given channel. The database is never an effective place to track a user's logged in status, as a user can simply close their browser, effectively making them logged out, but the database will not know about it. You can do something like look at a user's last activity and update that on every request, but this type of method would not account for a user that sits idle for a long amount of time without logging out, but is still available for chat. The system would look at their last action time and think they were logged out, when they're not.

So the only thing you can do reliably is to have an event broadcast channel open and then all other clients would have access to see the other active "listeners" to the channel. When a user closes their browser, it closes their connection to the channel, which then immediately propagates to all the other users. If you don't know about these types of event based channel capabilities built into Laravel, I'd really suggest you watch Jeffrey Way's laracasts on Laravel Echo. It's easier to implement on newer versions of Laravel, but very powerful stuff.

Search trademark database, Search for trademark applications and registrations with Trademark Check other sources, such as state trademark databases and the internet� You can also check the status of your one-time coronavirus stimulus check. How to Check Your Refund Status. Use the Where's My Refund tool or the IRS2Go mobile app to check your refund online. This is the fastest and easiest way to track your refund. The systems are updated once every 24 hours. You can call the IRS to

From the Laravel documentation found here.

Determining If The Current User Is Authenticated

To determine if the user is already logged into your application, you may use the check method on the Auth facade, which will return true if the user is authenticated:

if (Auth::check()) {
    // The user is logged in... 
}

Check Your Service and Support Coverage, Check your Apple warranty status. Enter a serial number to review your eligibility for support and extended coverage. Plagiarism Checking Grammarly’s plagiarism checker can detect plagiarism from billions of web pages as well as from ProQuest’s academic databases. Our free plagiarism check will tell you whether or not your text contains duplicate content.

Check for an existing account - Google Account Help, Check for an existing account. If you're trying to sign in, but don't remember your username or aren't sure if you created an account, try recovering your� Owners may not always know their recalled vehicle still needs to be repaired. NHTSA's new search tool lets you enter a Vehicle Identification Number (VIN) to quickly learn if a specific vehicle has not been repaired as part of a safety recall in the last 15 years.

Checking Account Definition, The tradeoff for increased liquidity is that checking accounts don't offer holders much, if any, interest. Money can be deposited at banks and via� The Google Translate feature is a third-party service that is available for informational purposes only. Fannie Mae is unable to guarantee the accuracy of any translation resulting from the tool and is not responsible for any event or damage that occurs as a result of using the translations generated by the Google Translate feature.

Checking if an equation represents a function (video), So one way you could think about it is you could essentially try to solve for y here. So let's do Duration: 3:33 Posted: Aug 17, 2015 1. To check if a domain name is available, just type it in GoDaddy 's search bar and we'll tell you immediately if it's already owned by someone else. 2. If it's taken, you can search for your domain name using our WHOIS Lookup. 3. Or try our Domain Broker Service, where we can negotiate acquiring the domain from its current owner.

Comments
  • You can use Session::set() and Session::get() methods to handle the login.And finally can use Session::flush() method in Laravel to logout the user.
  • I think that's a poor solution compared to mine, as there is a lot of logic in the Authentication trait that does not run. Also It's a lot more complex compared to using events!
  • I don't think that works, as those methods don't even run! I put dd("hi)` at the top of the methods, and they did not run! The example in my code was just an example. I need a place to put my code
  • How did you log in the user
  • using Route::get('login', 'Auth\AuthController@getLogin')->name('login'); and I didn't create a method called "getLogin". It did it automatically!
  • use this to log in if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) { // The user is active, not suspended, and exists. }
  • Can u put it in ur answer as I can't see it properly informatted
  • But it won't help in determining if other users are logged in. I'm creating like a chat application.