Download the PHP package mrnewport/laravel-priceable without Composer

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

mrnewport/laravel-priceable

mrnewport/laravel-priceable is a Laravel package that provides quantity-based, multi-scope pricing for any Eloquent model. It allows you to define tiered pricing, attach custom price lists to specific users, and apply additional “scopes” (like region or channel) without the need for external dependencies.

This README walks you through installation, configuration, usage, advanced features, and testing.


Table of Contents

  1. Introduction
  2. Key Features
  3. Requirements
  4. Installation
  5. Configuration
  6. Migrations
  7. Usage
    • Attaching the Priceable Trait
    • Defining Tiered Pricing
    • Price Lists & User-Specific Pricing
    • Scopes (Region, Channel, etc.)
    • Retrieving a Price
  8. Fallback Logic & Exception Handling
  9. Advanced: Date-Range Pricing
  10. Testing
  11. License

Introduction

MrNewport/LaravelPriceable offers a complete and robust solution for dynamic pricing in your Laravel application. By simply adding a trait to any Eloquent model, you can define:

Everything is self-contained, including the test suite, which uses an in-memory SQLite database and does not rely on your host application’s models or migrations.


Key Features


Requirements


Installation

  1. Require via Composer:

  2. Optional: Publish the package config and migrations into your Laravel app (if you want to customize them in your project):

  3. Run Migrations (if you published them or are auto-loading them):

  4. Configure (Optional): If you want the package to auto-load its migrations instead of publishing them, set auto_load_migrations to true in config/priceable.php.

Configuration

The package ships with a configuration file located at:

When published, it appears in your Laravel app’s config/priceable.php. Key settings include:


Migrations

All migration files reside in:

If auto_load_migrations is set to false (default), you should publish and run them from your main Laravel application. Alternatively, set auto_load_migrations to true to have them loaded directly from this package.

These migrations create:

  1. price_lists: Names and descriptions for your custom or default price lists (e.g., “VIP”, “Corporate”).
  2. price_list_user: A pivot table linking users to price lists.
  3. prices: Stores tier-based pricing, including quantity ranges, currency, and optional date ranges.
  4. price_scopes: Key-value pairs (e.g., region=US, channel=B2B) for more granular pricing logic.

Usage

Attaching the Priceable Trait

Any Eloquent model you wish to have dynamic pricing must use the Priceable trait:

This adds a polymorphic relationship to the prices table, letting you define multiple tiered prices for each product (or any other model).


Defining Tiered Pricing

You can define multiple quantity ranges by creating records in the prices relationship:

If someone purchases 5 units, the price is $100; for 15 units, $80.


Price Lists & User-Specific Pricing

If you want specialized pricing for certain users:

  1. Create a Price List:

  2. Attach a user to that list:

  3. Add special prices under that price list:

When you call $product->priceFor(5, $user), the package checks the user’s VIP price list first, and if found, uses $60.


Scopes (Region, Channel, etc.)

You can attach key-value scopes to any price. For instance, define a region=US or channel=B2B scope:

When retrieving the price, pass scopes as an associative array:

Only prices containing all matching scopes (region=US) will be considered. If none match, it falls back as configured.


Retrieving a Price

To get a final price, call priceFor($quantity, $user, $scopes = []):

Alternatively, you can use:

  1. Facade:

  2. Helper:

Fallback Logic & Exception Handling

If a user has no custom price (or no matching scope), the system can fallback to a default price (price_list_id = null). You can control this behavior via config:

This ensures you never end up with an undefined or zero price unless you explicitly allow it.


Advanced: Date-Range Pricing

Each price record can optionally have valid_from and valid_to fields:

If the current date/time is outside that range, the system ignores this price.


Testing

The tests are completely self-contained and use in-memory SQLite. No external references to your application’s models or factories.

To run tests:

How It Works

This ensures the package is thoroughly verified in isolation.


License

This package is open-sourced software licensed under the MIT license.

Enjoy using MrNewport/LaravelPriceable for your advanced pricing needs!


All versions of laravel-priceable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ^9.0|^10.0|^11.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 mrnewport/laravel-priceable contains the following files

Loading the files please wait ....