All Projects → overtrue → laravel-revaluation

overtrue / laravel-revaluation

Licence: MIT license
Laravel 5 model revaluation helper.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-revaluation

laravel-sms
Laravel 贴合实际需求同时满足多种通道的短信发送组件
Stars: ✭ 67 (+116.13%)
Mutual labels:  laravel-5-package
laravel-geometry
SPINEN's Laravel wrapper over geoPHP
Stars: ✭ 36 (+16.13%)
Mutual labels:  laravel-5-package
laravel-browsershot
Browsershot wrapper for Laravel 5
Stars: ✭ 108 (+248.39%)
Mutual labels:  laravel-5-package
laravel-vue-component
A Blade directive to ease up Vue workflow for Laravel projects
Stars: ✭ 19 (-38.71%)
Mutual labels:  laravel-5-package
querydumper
Laravel package to dump all running queries on the page.
Stars: ✭ 24 (-22.58%)
Mutual labels:  laravel-5-package
content-management-system
Content management system for laravel developers'. It's easy to install and run.
Stars: ✭ 16 (-48.39%)
Mutual labels:  laravel-5-package
laravel-payfort
Laravel Payfort provides a simple and rich way to perform and handle operations for Payfort online payment gateway
Stars: ✭ 14 (-54.84%)
Mutual labels:  laravel-5-package
laravel-zxcvbn
Implementation of the zxcvbn project by @dropbox for Laravel.
Stars: ✭ 24 (-22.58%)
Mutual labels:  laravel-5-package
laravel-site-protection
Protect your site with a simple password form
Stars: ✭ 38 (+22.58%)
Mutual labels:  laravel-5-package
laravel-storyblok
Make Laravel and Storyblok work together beautifully.
Stars: ✭ 45 (+45.16%)
Mutual labels:  laravel-5-package
baserepo
Base repository
Stars: ✭ 71 (+129.03%)
Mutual labels:  laravel-5-package
magic-box
A magical implementation of Laravel's Eloquent models as injectable, masked resource repositories.
Stars: ✭ 46 (+48.39%)
Mutual labels:  laravel-5-package
collage
Generate Image Collage with PHP and Laravel
Stars: ✭ 70 (+125.81%)
Mutual labels:  laravel-5-package
sweetalert
Laravel 5 Package for SweetAlert2. Use this package to easily show sweetalert2 prompts in your laravel app.
Stars: ✭ 28 (-9.68%)
Mutual labels:  laravel-5-package
correios-consulta
Buscar informações de serviços dos correios diretamente nos sites deles, sem utilizar api de terceiros.
Stars: ✭ 155 (+400%)
Mutual labels:  laravel-5-package
Laralang
This package lets you translate any string to multiple languages easily in laravel 5.4
Stars: ✭ 45 (+45.16%)
Mutual labels:  laravel-5-package
laravel-email-exceptions
Email Exceptions package for Laravel 5.x
Stars: ✭ 33 (+6.45%)
Mutual labels:  laravel-5-package
laravel-firebase
Laravel FCM (Firebase Cloud Messaging) Notification Channel
Stars: ✭ 25 (-19.35%)
Mutual labels:  laravel-5-package
mail-template
💌 This package is a easy to use mail template collection for Laravel 5.x.
Stars: ✭ 18 (-41.94%)
Mutual labels:  laravel-5-package
laravel-assetcachebuster
Laravel 5 package that prefixes asset urls with a unique hash which will allow invalidation of asset files cached by the browser.
Stars: ✭ 33 (+6.45%)
Mutual labels:  laravel-5-package

Laravel Revaluation

Laravel 5 model revaluation helper.

Build Status Latest Stable Version Latest Unstable Version Scrutinizer Code Quality Code Coverage Total Downloads License

Installation

You can install the package using composer

$ composer require overtrue/laravel-revaluation -vvv

Then add the service provider to config/app.php

Overtrue\LaravelRevaluation\RevaluationServiceProvider::class,

Publish the config file:

$ php artisan vendor:publish --provider='Overtrue\LaravelRevaluation\RevaluationServiceProvider'

Finally, use Overtrue\LaravelRevaluation\Traits\HasRevaluableAttributes in model. And specify which attributes in the $revaluable property can be revalued:

<?php

use Illuminate\Database\Eloquent\Model;
use Overtrue\LaravelRevaluation\Traits\HasRevaluableAttributes;

class Order extends Model
{
    use HasRevaluableAttributes;
    
    // 1. Use the default valuator.
    protected $revaluable = [
        'total', 'paid_in', 'postage',
    ];
    
    // 2. Use the specified valuator:
    // protected $revaluable = [
    //    'foo' => '\Foo\Support\Valuator\Foo',
    //    'bar' => '\Foo\Support\Valuator\Bar',
    //    'baz',  // default valuator
    //];

    //...
}

Usage

Basic usage with default options.

$order = Order::find(1);

$order->total;                      // 345 (Db: 34500)
$order->raw_total;                   // 34500

$order->getRevaluatedTotalAttribute() or $order->revaluated_total; // Overtrue\LaravelRevaluation\Valuators\RmbCent
$order->revaluated_total->inYuan();       // 345.00
$order->revaluated_total->asCurrency();   // ¥345.00

// automatic setter.
$order->total = 123;
$order->save();

$order->total;                      // 123
$order->raw_total;                  // 12300
$order->revaluated_total->asCurrency();   // ¥123.00

// to array
$order->toArray();
//[
//    'total' => 12300,
//    'revaluated_total' => 123.0,
//]

Custom revaluated attribute prefix

protected $revaluatedAttributePrefix = 'display';

$order->total;                      // 123.0;
$order->raw_total;                  // 12300
$order->display_total->asCurrency();   // ¥123.00

// to array
$order->toArray();
//[
//    'total' => 12300,
//    'display_total' => 123.0,
//]

Disable auto append revaluated attributes to array

protected $appendRevaluatedAttributesToArray = false;

$order->total;                      // 123.0;
$order->raw_total;                  // 12300
$order->display_total->asCurrency();   // ¥123.00

// to array
$order->toArray();
//[
//    'total' => 12300,
//]

Using revaluated value replace raw attributes value

protected $replaceRawAttributesToArray = true;

$order->total;                      // 123.0;
$order->raw_total;                  // 12300
$order->display_total->asCurrency();   // ¥123.00

// to array
$order->toArray();
//[
//    'total' => 123.0,
//]

More usage examples, Please refer to unit testing

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].