PHPackages                             qskousen/calculated-field - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. qskousen/calculated-field

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

qskousen/calculated-field
=========================

A server side calculated field for Laravel Nova

025

Since Aug 5Pushed 2y agoCompare

[ Source](https://github.com/alexander-zugan/calculated-field)[ Packagist](https://packagist.org/packages/qskousen/calculated-field)[ RSS](/packages/qskousen-calculated-field/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

A Server-Side Calculated Field For Laravel Nova
===============================================

[](#a-server-side-calculated-field-for-laravel-nova)

**Note from Qskousen:**

I've just updated this package to work for Nova 4, all the credit still belongs to codebykyle for their original work here:

**Changes:**

Removed dependency on outdated `numeral` package. Instead, it will format using [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat).

In light of that, the `->numberFormat()` function signature has changed to `->numberFormat($format, $locale = 'en-US')`, where `$format` is a valid format JSON string from `Intl.NumberFormat` (link above), for example, `->numberFormat("{style: 'currency', currency: 'usd'}")`. In this instance, the locale is left to default of `en-US`.

The formatting only works in some specific scenarios. Doesn't work very well except on a readonly listener field. I don't think this was fully implemented in codebykyle's version, which is probably why it wasn't in the readme. Results may vary.

**Original readme follows**

This package contains two Nova fields required to do server-side calculations from the Nova client. The user can optionally override the calculated value on the form.

For a detailed write-up of the how-and-why of this field, please visit:

Installation
------------

[](#installation)

Install the package via composer:

`composer require codebykyle/calculated-field`

### Example

[](#example)

For example:

#### As a number

[](#as-a-number)

[![Calculated Number Field](https://camo.githubusercontent.com/6d65b948151cd634d1671b1e21f2d0b5d51b86a2f504ef685f094b6efa7f1bee/68747470733a2f2f63626b2d776562736974652e73332e616d617a6f6e6177732e636f6d2f63616c63756c617465642d6669656c642f6e756d6265725f63616c635f6669656c642e676966 "Calculated Number Field")](https://camo.githubusercontent.com/6d65b948151cd634d1671b1e21f2d0b5d51b86a2f504ef685f094b6efa7f1bee/68747470733a2f2f63626b2d776562736974652e73332e616d617a6f6e6177732e636f6d2f63616c63756c617465642d6669656c642f6e756d6265725f63616c635f6669656c642e676966)

#### As a string:

[](#as-a-string)

[![Calculated String Field](https://camo.githubusercontent.com/65e4edfbdbbcbf82b58c6d18ddc76b0ebc843ac07b75fd69b521aa47598e575f/68747470733a2f2f63626b2d776562736974652e73332e616d617a6f6e6177732e636f6d2f63616c63756c617465642d6669656c642f737472696e675f63616c635f6669656c642e676966 "Calculated String Field")](https://camo.githubusercontent.com/65e4edfbdbbcbf82b58c6d18ddc76b0ebc843ac07b75fd69b521aa47598e575f/68747470733a2f2f63626b2d776562736974652e73332e616d617a6f6e6177732e636f6d2f63616c63756c617465642d6669656c642f737472696e675f63616c635f6669656c642e676966)

##### Default

[](#default)

The Listener field will by default sum all numbers passed to it

### Usage

[](#usage)

```
