Download the PHP package shetabit/token-builder without Composer

On this page you can find all versions of the php package shetabit/token-builder. 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 token-builder

Laravel Token Builder

Latest Version on Packagist Total Downloads on Packagist Tests Code Style Static Analysis Code Coverage

This package requires PHP 8.4+ and supports Laravel 12 and Laravel 13.

This package can generate random tokens which can expires.

Generated token can be used for creating one-time links, or authentication with sms pin and etc.

we have 2 things that can expire genereted tokens:

Donate me if you like this package :sunglasses: :bowtie:

List of contents

Install

Via Composer

Configure

The service provider and the TokenBuilder alias are registered by Laravel's package discovery, so there is nothing to add to config/app.php (or to bootstrap/providers.php).

Run the below commands to publish migrations and create tables

How to use

you can use TokenBuilder facade or Builder class to build tokens.

Generating tokens

In your code, use facade like the below :

you can also use Builder :

each tokenObject has a unique value that can be used to recognize it from others and we call it token. you can access to tokenObject unique token using token, see below example:

you can retrieve token and send it to users via email or sms or using it in URLs. it can be used to sms verifications or one-time login pins , etc.

Adding expiration date

you can build a token with auto expiration date. this kind of token will be expired after the specified date.

Adding usage limit

you can add usage limit into your tokens. a token will be invalid after the usage has exceeded the limit.

Validation

you can validate a token using isValid method. a token is valid if has not exceeded the specified limit and has not expired yet.

you can use a token by running use method. you can expire a token by running markAsExpired method. (this method will update expiration date to current date).

Add relations

you can add a relation to tokens. this can be done in 2 different ways:

Attach custom data

you can attach custom data into your token. this data will be stored in json format.

Retrieve tokens

you can retrieve tokenObject using token's unique string

The valid tokens of a model

sometimes you don't have a token yet and want to know whether a model still has one that is valid: a forgot password pin should not be sent again while the one that was sent is still usable.

a model that uses the HasTemporaryTokens trait can answer that itself:

so a pin is only built when there is none left:

the TokenBuilder answers the same questions, and without a relation it looks at the tokens of every model:

notice: findValidTokens and hasAnyValidToken ask whether there is any valid token, so they ignore setUniqueId. use findValidToken or isValid to validate a token you have.

TokenBuilder reference

This is a reference for TokenBuilder methods. TokenBuilder creates a tokenObject (instance of eloquent Token model) if you run build method and searches into data base using findToken and findValidToken.

Model Reference

these methods are added to your own models by the Shetabit\TokenBuilder\Traits\HasTemporaryTokens trait.

Token Reference

Testing

Every pull request and every push to master is checked by GitHub Actions: the test suite runs on PHP 8.4 and 8.5, against Laravel 12 and 13 and against both the lowest and the highest supported dependencies, the coding style is checked with PHP_CodeSniffer, the sources are analysed with PHPStan (level 7, with larastan) and the code coverage of the test suite is measured and has to stay above 95%.

The suite has two parts: tests/Unit covers the builder, the token, the repository, the token trait and the provider on their own, and tests/Feature runs the flows of this readme end to end against a database.

You can run the same checks locally. With PHP and Composer installed on your machine:

If you would rather not install PHP on your machine, the shipped Dockerfile and Makefile run everything inside a container:

Another PHP version can be used with make test PHP_VERSION=8.5, and a single Laravel version with make test-laravel LARAVEL=12.

Change log

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of token-builder with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
illuminate/database Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
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 shetabit/token-builder contains the following files

Loading the files please wait ...