Download the PHP package hao-li/laravel-amount without Composer

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

laravel-amount

Total Downloads Latest Stable Version License

背景

系统中涉及到金额的字段,View 层表现的时候一般都是以为单位使用小数形式展示,不过 Domain 层存储时从空间、性能、容错角度出发,经常以为单位,用整型来存储。

在 Lavarel 中,可以在 Model 中添加属性方法进行转换

不过涉及金额的字段比较多时就需要定义很多相同逻辑的函数,本项目即将该逻辑抽出为 Trait,简化金额字段相关的处理。

除了金额外,小数位数固定的面积长度等场景使用起来也很方便。

原理

将转换逻辑封装在 AmountTrait 中,覆写 Model 类的 getMutatedAttributes, mutateAttributeForArray, getAttributeValue 及 setAttribute 方法,当访问相关字段时自动进行转换处理。

依赖

Laravel >= 5.2

安装

使用

  1. 在 Model 中引用 AmountTrait

  2. 使用 AmountTrait

  3. 定义金额字段(本例中为 amount)

  4. 通过 $amountTimes 指定金额字段的倍数(可选,默认 100)

    • 各金额字段使用相同的倍数

    • 不同金额字段设置不同倍数
  5. 完成

    之后读取 amount 字段时,该字段的内容会自动从数据库的转换为,向其赋值时反之从转换为

FAQ

和别的 trait 中方法冲突

以 setRawAttributes 为例(此为之前方案,目前并未覆写此方法,仅为举例,其他方法原理相同)

  1. 将冲突的方法分别重命名

  2. 在 Model 中定义该冲突的方法,根据情况分别调用别名方法

    注意这里 $attributes 可能已被改变,所以再次使用时要重新取得最新值


All versions of laravel-amount with dependencies

PHP Build Version
Package Version
No informations.
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 hao-li/laravel-amount contains the following files

Loading the files please wait ....