Code Monkey home page Code Monkey logo

active-users's Introduction

A Laravel Package for easily retrieving a list of active users and guests that are currently online.

This is a small, simple little package for seeing who's currently online.

Installation

Install via composer with:

composer require joshrainwater/active-users

Setup

Sessions and Database

For now, this package only supports the 'database' type for session storage. Open your .env file and change the session driver to database:

SESSION_DRIVER=database

and also make sure to publish the default session table with:

php artisan session:table

php artisan migrate

Providers and Aliases

In order to use the Active class, reference the full vendor namespace, or just import the class at the top of the file that you want to use it in. Eg:

\Rainwater\Active\Active::users();

or

use Rainwater\Active\Active;
Active::users();

This package also includes a provider and alias to make things easier. To set those up properly, open config/app.php and add this to your providers array:

Rainwater\Active\ActiveServiceProvider::class

and this to your aliases array:

'Active' => Rainwater\Active\ActiveFacade::class

Usage

Grabbing Most Recent Activities

Import the Active facade at the top and then do a simple query.

// Import at the top
use Active;


// Find latest users
$users = Active::users()->get();

// Loop through and echo user's name
foreach ($users as $activity) {
    echo $activity->user->name . '<br>';
}

By default, the 'users' method will return users that have been active in the past 5 minutes. If you want to display a different timespan, use the following functions:

$users = Active::users(3)->get();   				// Last 3 minutes
$users = Active::usersWithinSeconds(30)->get();  	// Get active users within the last 30 seconds
$users = Active::usersWithinMinutes(10)->get();  	// Get active users within the last 10 minutes
$users = Active::usersWithinHours(1)->get();     	// Get active users within the last 1 hour

The functions listed above all return Eloquent Queries, so you can do anything with the results that would do with any other model:

$numberOfUsers = Active::users()->count();        // Count the number of active users

Sorting Methods

There are a couple convenience methods for sorting results, as well:

$users = Active::users()->mostRecent()->get();   // Get active users and sort them by most recent
$users = Active::users()->orderByUsers('email')->get(); // Sort by the email column on the users table.

Guests

You can also view online guests with all the same methods as users above:

$guests = Active::guests(1)->get();   				// Last 1 minute
$guests = Active::guests(3)->get();   				// Last 3 minutes
$guests = Active::guestsWithinSeconds(30)->get();  	// Get active guests within the last 30 seconds
$guests = Active::guestsWithinMinutes(10)->get();  	// Get active guests within the last 10 minutes
$guests = Active::guestsWithinHours(1)->get();     	// Get active guests within the last 1 hour

$numberOfGuests = Active::guests()->count();      // Count the number of active guests

Many thanks to thomastkim/laravel-online-users on which this is very heavily based.

License

This package is free software distributed under the terms of the MIT license.

active-users's People

Contributors

divdax avatar dylan-dpc avatar holonist avatar jeremykenedy avatar joshrainwater avatar kalimeromk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

active-users's Issues

Can not install due to libcrypto library not found

Any help? I tried updating and upgrading brew and then reinstalling OpenSSL but didn't work. This is what I get.

$ composer require joshrainwater/active-users
dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
Referenced from: /usr/local/bin/php
Reason: image not found
Abort trap: 6

API Active Users?

When using a REST API for a SPA then users don't show up active.
Is there any way to see active logged in users also including SPA users?

Laravel Framework 7.10.3 compability

Hey, I really would like to try out the package, but I can't install on Laravel Framework 7.10.3 because it requires illuminate/support. Can you please fix the compability?

"illuminate/support": "7.*",

methods

Hello
How do I know if an online user is online or offline?
For example, there are no methods such as isonline( ) or isactive( )?
I now have a forech( ) of all my friends and I want to show everyone online. How're you?

Cannot use orderByUsers function to sort active users. Throws error Call to undefined method Illuminate\Database\Eloquent\Builder::orderByUsers()

Trying to sort users by using this method and it fails. Below is the log.

production.ERROR: Call to undefined method Illuminate\Database\Eloquent\Builder::orderByUsers() {"userId":336,"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method Illuminate\\Database\\Eloquent\\Builder::orderByUsers() at C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Traits\\ForwardsCalls.php:50)
[stacktrace]
#0 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Traits\\ForwardsCalls.php(36): Illuminate\\Database\\Eloquent\\Builder::throwBadMethodCallException('orderByUsers')
#1 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Builder.php(1356): Illuminate\\Database\\Eloquent\\Builder->forwardCallTo(Object(Illuminate\\Database\\Query\\Builder), 'orderByUsers', Array)
#2 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\app\\Http\\Controllers\\HomeController.php(101): Illuminate\\Database\\Eloquent\\Builder->__call('orderByUsers', Array)
#3 [internal function]: App\\Http\\Controllers\\HomeController->getPublicChat(Object(Illuminate\\Http\\Request))
#4 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php(54): call_user_func_array(Array, Array)
#5 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('getPublicChat', Array)
#6 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(219): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\HomeController), 'getPublicChat')
#7 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(176): Illuminate\\Routing\\Route->runController()
#8 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(680): Illuminate\\Routing\\Route->run()
#9 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(30): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#10 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\SubstituteBindings.php(41): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#11 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#12 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#13 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Auth\\Middleware\\Authenticate.php(43): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#14 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Auth\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#15 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#16 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php(75): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#17 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#18 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#19 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Middleware\\ShareErrorsFromSession.php(49): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#20 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#21 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#22 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(56): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#23 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#24 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#25 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse.php(37): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#26 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#27 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#28 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\EncryptCookies.php(66): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#29 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#30 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#31 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#32 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(682): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#33 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(657): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#34 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(623): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#35 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(612): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#36 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#37 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#38 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#39 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#40 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#41 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#42 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#43 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#44 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#45 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#46 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#47 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(62): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#48 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#49 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#50 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\fideloper\\proxy\\src\\TrustProxies.php(57): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#51 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#52 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#53 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#54 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#55 C:\\xampp\\htdocs\\homebrew\\chatni\\_chat\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#56 C:\\xampp\\htdocs\\homebrew\\chatni\\index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#57 {main}
"} 

Anything I need to check before calling this function?

Wron façade in documentation

Hi,

I've install this package in my project but it could not work first when i simply follow install instructions that are in the doc.
The problem was refering to a missing façade.
When i inspected the source code, i found out that you used a different faça de name in the documentation. Especially, you used this 'Active' => Rainwater\Active\ActivityFacade::class instead of your façade that is actually named "ActiveFacade".

I think you used the façade name of the parent project https://github.com/thomastkim/laravel-online-users

Hope u'll correct it in the documentation very soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.