Download the PHP package climactic/laravel-credits without Composer

On this page you can find all versions of the php package climactic/laravel-credits. 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 laravel-credits

# Laravel Credits A ledger-based Laravel package for managing credit-based systems in your application. Perfect for virtual currencies, reward points, or any credit-based feature. [![Discord](https://img.shields.io/discord/303195322514014210?style=for-the-badge)](https://discord.gg/kedWdzwwR5) [![Latest Version on Packagist](https://img.shields.io/packagist/v/climactic/laravel-credits.svg?style=for-the-badge)](https://packagist.org/packages/climactic/laravel-credits) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/climactic/laravel-credits/run-tests.yml?branch=main&label=tests&style=for-the-badge)](https://github.com/climactic/laravel-credits/actions?query=workflow%3Arun-tests+branch%3Amain) [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/climactic/laravel-credits/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=for-the-badge)](https://github.com/climactic/laravel-credits/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/climactic/laravel-credits.svg?style=for-the-badge)](https://packagist.org/packages/climactic/laravel-credits) ![Depfu](https://img.shields.io/depfu/dependencies/github/Climactic%2Flaravel-credits?style=for-the-badge) [![Sponsor on GitHub](https://img.shields.io/badge/Sponsor-GitHub-ea4aaa?style=for-the-badge&logo=github)](https://github.com/sponsors/climactic) [![Support on Ko-fi](https://img.shields.io/badge/Support-Ko--fi-FF5E5B?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/ClimacticCo)

๐Ÿ“– Table of Contents

Features

๐ŸŒŸ Sponsors

Your logo here โ€” Become a sponsor and get your logo featured in this README and on our website.

Interested in title sponsorship? Contact us at [email protected] for premium placement and recognition.

๐Ÿ“ฆ Installation

You can install the package via composer:

Publish and run the migrations:

Optionally publish the config file:

โš™๏ธ Configuration

๐Ÿ—„๏ธ Database Recommendations

Concurrency & Locking: This package uses row-level locking (SELECT FOR UPDATE) to prevent race conditions during concurrent credit operations. This requires a database engine that supports proper transaction isolation and row-level locking:

For production environments with concurrent users, we recommend using MySQL/MariaDB (InnoDB) or PostgreSQL.

๐Ÿš€ Usage

๐Ÿ”ง Setup Your Model

Add the HasCredits trait to any model that should handle credits:

๐Ÿ’ณ Basic Usage

๐Ÿ’ธ Transfers

Transfer credits between two models:

๐Ÿ“Š Transaction History

๐Ÿ• Historical Balance

Get balance as of a specific date:

๐Ÿ“ Metadata

Add additional information to transactions:

๐Ÿ”Ž Querying by Metadata

The package provides powerful query scopes to filter transactions by metadata with built-in input validation for security.

Metadata Key Format

Metadata keys must follow these rules:

Basic Metadata Queries

Advanced Metadata Queries

Chaining Multiple Metadata Conditions

Convenience Methods

Note: When using creditHistoryWithMetadata(), the filter array distinguishes between "two-parameter syntax" and "three-parameter syntax" by checking if the 'value' key exists:

This allows proper handling of null values while maintaining shorthand syntax convenience.

โšก Performance Optimization

For high-volume applications querying metadata frequently, consider adding database indexes. Without indexes, metadata queries perform full table scans. With proper indexes, queries become nearly instant even with millions of records.

When to Optimize
MySQL/MariaDB: Virtual Columns with Indexes

Virtual generated columns extract JSON values into indexed columns for fast queries:

Performance impact: Queries go from scanning millions of rows to using index lookups (1000x+ faster).

PostgreSQL: GIN Indexes on JSONB

PostgreSQL's GIN (Generalized Inverted Index) provides efficient querying for all JSON operations:

Note: The GIN index alone enables fast queries for all metadata keys. Path-specific indexes provide marginal additional performance.

SQLite: Limited Support

SQLite has limited JSON indexing capabilities. For SQLite:

Choosing What to Index

Index metadata keys that you query frequently:

Best Practices
  1. Analyze your queries first: Use EXPLAIN to identify slow queries
  2. Index selectively: Only index frequently queried keys (each index adds storage overhead)
  3. Use composite indexes: For queries combining metadata with other columns
  4. Test with production data: Benchmark before and after indexing
  5. Monitor index usage: Remove unused indexes to save storage

๐Ÿ“ข Events

Events are fired for each credit transaction, transfer, and balance update.

The events are:

๐Ÿ“š API Reference

๐Ÿ”ง Available Methods

Method Description
creditAdd(float $amount, ?string $description = null, array $metadata = []) Add credits to the model
creditDeduct(float $amount, ?string $description = null, array $metadata = []) Deduct credits from the model
creditBalance() Get the current balance
creditTransfer(Model $recipient, float $amount, ?string $description = null, array $metadata = []) Transfer credits to another model
creditHistory(int $limit = 10, string $order = 'desc') Get transaction history
hasCredits(float $amount) Check if model has enough credits
creditBalanceAt(Carbon\|DateTimeInterface\|int $dateTime) Get balance at a specific time
credits() Eloquent relationship to credit transactions
creditsByMetadata(string $key, $operator, $value = null, int $limit = 10, string $order = 'desc') Get credits filtered by metadata key/value
creditHistoryWithMetadata(array $filters, int $limit = 10, string $order = 'desc') Get credits filtered by multiple metadata

๐Ÿ” Query Scopes

These scopes can be used on the credits() relationship:

Scope Description
whereMetadata(string $key, $operator, $value = null) Filter by metadata key/value
whereMetadataContains(string $key, $value) Filter where metadata array contains value
whereMetadataHas(string $key) Filter where metadata key exists
whereMetadataNull(string $key) Filter where metadata key is null/doesn't exist
whereMetadataLength(string $key, $operator, $value) Filter by metadata array length

โš ๏ธ Deprecated Methods

The following methods are deprecated and will be removed in v2.0. They still work but will trigger deprecation warnings:

Deprecated Method Use Instead
addCredits() creditAdd()
deductCredits() creditDeduct()
getCurrentBalance() creditBalance()
transferCredits() creditTransfer()
getTransactionHistory() creditHistory()
hasEnoughCredits() hasCredits()
getBalanceAsOf() creditBalanceAt()
creditTransactions() credits()

๐Ÿงช Testing

๐Ÿ“‹ Changelog

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

๐Ÿค Contributing

Please see CONTRIBUTING for details. You can also join our Discord server to discuss ideas and get help: Discord Invite.

๐Ÿ”’ Security Vulnerabilities

Please report security vulnerabilities to [email protected].

๐Ÿ’– Support This Project

Laravel Credits is free and open source, built and maintained with care. If this package has saved you development time or helped power your application, please consider supporting its continued development.

Sponsor on GitHub

 

Support on Ko-fi

โญ Star History

Star History Chart

๐Ÿ“„ License

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

โš–๏ธ Disclaimer

This package is not affiliated with Laravel. It's for Laravel but is not by Laravel. Laravel is a trademark of Taylor Otwell.


All versions of laravel-credits with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
spatie/laravel-package-tools Version ^1.92.7
illuminate/contracts Version ^12.43.1 || ^13.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 climactic/laravel-credits contains the following files

Loading the files please wait ...