PHPackages                             tawwfik/zakat-calculator - 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. tawwfik/zakat-calculator

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

tawwfik/zakat-calculator
========================

A Laravel package for calculating zakat on money, gold, and silver.

v1.1.0(11mo ago)1011[1 issues](https://github.com/tawwfik/Zakat-Calculator/issues)MITPHPPHP ^8.0

Since May 30Pushed 11mo agoCompare

[ Source](https://github.com/tawwfik/Zakat-Calculator)[ Packagist](https://packagist.org/packages/tawwfik/zakat-calculator)[ Docs](https://github.com/tawwfik/Zakat-Calculator)[ RSS](/packages/tawwfik-zakat-calculator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

Zakat Calculator for Laravel
============================

[](#zakat-calculator-for-laravel)

A comprehensive Laravel package for calculating zakat on various assets including money, gold, silver, business assets, and agricultural products. This package follows Islamic principles and supports multiple calculation methods.

Features
--------

[](#features)

- Calculate zakat on multiple asset types:
    - Cash and bank balances
    - Gold (supports multiple karats)
    - Silver
    - Business assets (inventory, receivables, cash)
    - Agricultural products
- Support for different calculation methods (Hanafi, Shafi'i, Maliki, Hanbali)
- Configurable nisab thresholds
- Real-time gold and silver price integration
- Detailed calculation breakdowns
- Caching support for better performance
- Comprehensive validation and error handling

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

[](#installation)

You can install the package via composer:

```
composer require tawwfik/zakat-calculator
```

The package will automatically register its service provider.

### Publishing Configuration

[](#publishing-configuration)

You can publish the configuration file using:

```
php artisan vendor:publish --provider="Tawfik\ZakatCalculator\ZakatServiceProvider" --tag="config"
```

This will create a `config/zakat.php` file in your config directory.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Tawfik\ZakatCalculator\ZakatCalculator;

class ZakatController extends Controller
{
    protected $calculator;

    public function __construct(ZakatCalculator $calculator)
    {
        $this->calculator = $calculator;
    }

    public function calculate(Request $request)
    {
        $result = $this->calculator
            ->setCash($request->cash)
            ->setGoldItems([
                ['weight' => 100, 'karat' => 24],
                ['weight' => 50, 'karat' => 18]
            ])
            ->setSilverWeight(500)
            ->setBusinessAssets([
                'inventory' => 5000,
                'receivables' => 2000,
                'cash_at_bank' => 3000
            ])
            ->setAgriculturalProducts([
                ['value' => 10000, 'irrigated' => true],
                ['value' => 20000, 'irrigated' => false]
            ])
            ->calculate();

        return response()->json($result);
    }
}
```

### Available Methods

[](#available-methods)

#### Asset Setting Methods

[](#asset-setting-methods)

- `setCash(float $cash)`: Set cash amount
- `setGoldItems(array $goldItems)`: Set gold items with weight and karat
- `setSilverWeight(float $silverWeight)`: Set silver weight
- `setGoldPrice(float $goldPrice)`: Set gold price per gram
- `setSilverPrice(float $silverPrice)`: Set silver price per gram
- `setBusinessAssets(array $assets)`: Set business assets
- `setAgriculturalProducts(array $products)`: Set agricultural products

#### Configuration Methods

[](#configuration-methods)

- `setCalculationMethod(string $method)`: Set calculation method (hanafi, shafi, maliki, hanbali)
- `setNisabThreshold(float $threshold)`: Set custom nisab threshold
- `setCacheEnabled(bool $enabled)`: Enable/disable caching
- `setCacheTTL(int $ttl)`: Set cache time-to-live in seconds

#### Calculation Methods

[](#calculation-methods)

- `calculate()`: Calculate total zakat
- `calculateCashZakat()`: Calculate zakat on cash only
- `calculateGoldZakat()`: Calculate zakat on gold only
- `calculateSilverZakat()`: Calculate zakat on silver only
- `calculateBusinessZakat()`: Calculate zakat on business assets only
- `calculateAgriculturalZakat()`: Calculate zakat on agricultural products only

### Calculation Result

[](#calculation-result)

The `calculate()` method returns an array with the following information:

```
[
    'total_assets' => [
        'cash' => float,
        'gold' => float,
        'silver' => float,
        'business' => float,
        'agricultural' => float
    ],
    'nisab_value' => float,
    'is_eligible' => boolean,
    'total_zakat' => float,
    'details' => [
        'cash' => [
            'amount' => float,
            'zakat' => float
        ],
        'gold' => [
            'items' => array,
            'total_weight' => float,
            'total_value' => float,
            'zakat' => float
        ],
        'silver' => [
            'weight' => float,
            'value' => float,
            'zakat' => float
        ],
        'business' => [
            'assets' => array,
            'total_value' => float,
            'zakat' => float
        ],
        'agricultural' => [
            'products' => array,
            'total_value' => float,
            'zakat' => float
        ]
    ],
    'calculation_method' => string
]
```

Configuration
-------------

[](#configuration)

After publishing the configuration file, you can customize the following settings in `config/zakat.php`:

### Default Prices

[](#default-prices)

```
'default_prices' => [
    'gold'   => 0.00, // Set your default gold price per gram
    'silver' => 0.00, // Set your default silver price per gram
],
```

### Nisab Thresholds

[](#nisab-thresholds)

```
'nisab' => [
    'gold'   => 85,  // grams of gold
    'silver' => 595, // grams of silver
],
```

### Currency Settings

[](#currency-settings)

```
'currency' => [
    'code'     => 'SAR',    // Currency code
    'symbol'   => 'ر.س',      // Currency symbol
    'position' => 'before', // Symbol position: 'before' or 'after'
],
```

### Weight Unit

[](#weight-unit)

```
'weight_unit' => 'gram', // 'gram' or 'ounce'
```

### Calculation Precision

[](#calculation-precision)

```
'precision' => 2, // Number of decimal places
```

### Supported Gold Karats

[](#supported-gold-karats)

```
'supported_karats' => [24, 22, 21, 18, 14, 12, 10],
```

### Cache Settings

[](#cache-settings)

```
'cache' => [
    'enabled' => true,
    'ttl'     => 3600, // Cache time-to-live in seconds
],
```

### Calculation Methods

[](#calculation-methods-1)

```
'calculation_methods' => [
    'default' => 'hanafi', // Available: 'hanafi', 'shafi', 'maliki', 'hanbali'
],
```

### Business Assets

[](#business-assets)

```
'business' => [
    'inventory'    => true,    // Include inventory in calculation
    'receivables'  => true,    // Include receivables in calculation
    'cash_at_bank' => true,    // Include bank cash in calculation
    'cash_in_hand' => true,    // Include cash in hand in calculation
],
```

### Agricultural Products

[](#agricultural-products)

```
'agricultural' => [
    'irrigated_rate'     => 0.05, // 5% rate for irrigated crops
    'non_irrigated_rate' => 0.1,  // 10% rate for non-irrigated crops
],
```

Advanced Usage Examples
-----------------------

[](#advanced-usage-examples)

### Calculating Zakat for Gold Only

[](#calculating-zakat-for-gold-only)

```
$result = $calculator
    ->setGoldItems([
        ['weight' => 100, 'karat' => 24],
        ['weight' => 50, 'karat' => 18]
    ])
    ->setGoldPrice(100) // Price per gram
    ->calculateGoldZakat();
```

### Calculating Business Zakat

[](#calculating-business-zakat)

```
$result = $calculator
    ->setBusinessAssets([
        'inventory' => 5000,
        'receivables' => 2000,
        'cash_at_bank' => 3000,
        'cash_in_hand' => 1000
    ])
    ->calculateBusinessZakat();
```

### Calculating Agricultural Zakat

[](#calculating-agricultural-zakat)

```
$result = $calculator
    ->setAgriculturalProducts([
        ['value' => 10000, 'irrigated' => true],  // Irrigated crops (5%)
        ['value' => 20000, 'irrigated' => false]  // Non-irrigated crops (10%)
    ])
    ->calculateAgriculturalZakat();
```

### Using Different Calculation Methods

[](#using-different-calculation-methods)

```
$result = $calculator
    ->setCalculationMethod('shafi')
    ->setCash(10000)
    ->setGoldItems([['weight' => 100, 'karat' => 24]])
    ->calculate();
```

Error Handling
--------------

[](#error-handling)

The package throws specific exceptions for different error cases:

- `InvalidInputException`: Thrown for invalid input values
- `InvalidKaratException`: Thrown for unsupported gold karats
- `ConfigurationException`: Thrown for missing or invalid configuration

Example error handling:

```
use Tawfik\ZakatCalculator\Exceptions\InvalidInputException;

try {
    $result = $calculator->setCash(-1000)->calculate();
} catch (InvalidInputException $e) {
    return response()->json(['error' => $e->getMessage()], 400);
}
```

Testing
-------

[](#testing)

Run the tests using:

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance50

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~16 days

Total

2

Last Release

332d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a18e9f7245abaa6e73b18372aee61cfe840b86f5ccc629bddf00f28ecf56893?d=identicon)[tawwfik](/maintainers/tawwfik)

---

Top Contributors

[![tawwfik](https://avatars.githubusercontent.com/u/55286777?v=4)](https://github.com/tawwfik "tawwfik (13 commits)")

---

Tags

zakatzakat-calculatorlaravelmoneycalculatorgoldsilverislamiczakat

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tawwfik-zakat-calculator/health.svg)

```
[![Health](https://phpackages.com/badges/tawwfik-zakat-calculator/health.svg)](https://phpackages.com/packages/tawwfik-zakat-calculator)
```

###  Alternatives

[laravolt/avatar

Turn name, email, and any other string into initial-based avatar or gravatar.

2.0k5.4M31](/packages/laravolt-avatar)[akaunting/laravel-money

Currency formatting and conversion package for Laravel

7825.3M18](/packages/akaunting-laravel-money)[prologue/alerts

Prologue Alerts is a package that handles global site messages.

3486.1M30](/packages/prologue-alerts)[watson/active

Laravel helper for recognising the current route, controller and action

3253.6M14](/packages/watson-active)[torann/currency

This provides Laravel with currency functions such as currency formatting and conversion using up-to-date exchange rates.

4081.1M6](/packages/torann-currency)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
