Download the PHP package dev-moez/auth-last-activity without Composer

On this page you can find all versions of the php package dev-moez/auth-last-activity. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package auth-last-activity

Auth Last Activity

👱 🕑 Multi-auth last activity laravel package

Table of contents

:book: Introduction

AuthLastActivity is a Laravel package that supports multiple authentication guards to record the last activity for your application users.

:sparkles: Features

:toolbox: Installation

You can install the package via composer:

The package will automatically register itself.

And to publish the config and the migration files needed for the package, run the following artisan command:

Or Manually:

You can publish the config file using the following command:

This is the contents of the published config file:

You can publish the migration file using the following command:

After publishing the migration file, you can create the user_last_activities table by running the migrations:

:gear: Configuration

Step 1

To start using the package you have to add the middleware AuthLastActivityMiddleware to your Kernel.php which is located in your project's app\Http directory.

And to make sure that all requests via web or api are considered, you should add that middleware in both arrays web & api, like so:

Step 2

Add HasLastActivity trait to each authenticatable model you have in your laravel project, like User and any other model you would use for a different guard for authentication, example on User model:

After doing this, you are ready to go :rocket:!

:rocket: Usage

Getting User Last Activity

Once you have installed and configured the package, it will automatically track the last activity time of authenticated users through your application. You can access the last activity time using the lastActivity one-to-one relation on the User model - or any other authenticatable models e.g: Admin ...etc, like so:

This will return a collection of the last activity data:

Getting User Status

To get the online status of a user you can use a method called isOnline to do so:

Getting Online Users

To get all online users you can use a static method called getOnline, like:

Getting Offline Users

To get all offline users you can use a static method called getOffline, like:

Please note that getting online and offline users are based on the seconds value of online-period which you can find in the auth-last-activity.php config file.

Getting Online Users Within Period

To get online users within a custom period of seconds you can use the static method of activeWithin(int $seconds) giving the seconds that you want to use.

Again, this will return the eloquent builder not the collection for the User model within the last two minutes. If you want the collection then follow the previous code with ->get():

Getting User Online Status Using cache

To get the online status of a user using cache, you can do by passing true to the argument of viaCahce in the isOnline method:

Or in your code you can use the following piece of code to achieve that:

What is the authenticatable name?

It's the kebab/lowercase of your model's base name.
Let's say your project has two authenticatable models:

  1. User the default authenticatable model for users in any laravel project
  2. Admin which you created for another guard just for administrators

Then for the first case the $authenticatable_name should be 'user' and for the second case the $authenticatable_name should be 'admin'.

And the $authenticatable_id is the primary key for this record in the database for sure. Examples:

You can get the authenticatable name for any authenticatable model using a static method called getAuthenticatableName().

:question: Why this package returns the Eloquent Builder not a Collection?
This approach is suitable for large datasets as it retrieves only the necessary data from the database, making it faster and more efficient. So if you would like to make any further operations such as filtering, mapping ...etc, it would be better to perform on a builder not a collection, after finishing you can call get() method to return the collection.

Updating

Want to update to the latest version?

Uninstallation

License

The MIT License (MIT).

Contributing

Contributions are welcome! If you would like to contribute to the package with a new feature or any other enhancement, please fork the repository and submit a pull request.

  1. Fork the Project
  2. Create your feature branch (git checkout -b feature/new-feature-name)
  3. Commit your changes (git commit -m 'Add and extra feature')
  4. Push to the branch (git push origin feature/new-feature-name)
  5. Open a pull request

And be sure that any contributions or comments you make are highly appreciated.

Contact

Abdelrahman Moez (aka Moez) - [email protected]


All versions of auth-last-activity with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dev-moez/auth-last-activity contains the following files

Loading the files please wait ....