PHPackages                             hitaqnia/haykal-core - 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. hitaqnia/haykal-core

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

hitaqnia/haykal-core
====================

Haykal shared utilities: Result pattern, tenancy primitives, phone-number value object, and two HTTP middlewares (user-locale + Spatie permissions-team bridge).

v2.0.4(1mo ago)045↓50%2proprietaryPHPPHP ^8.3

Since Apr 25Pushed 1mo agoCompare

[ Source](https://github.com/hitaqnia/haykal-core)[ Packagist](https://packagist.org/packages/hitaqnia/haykal-core)[ RSS](/packages/hitaqnia-haykal-core/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (4)Versions (7)Used By (2)

hitaqnia/haykal-core
====================

[](#hitaqniahaykal-core)

Shared utilities for HiTaqnia Laravel applications.

`haykal-core` is a **pure utility package**. It carries the cross-project primitives every hitaqnia app leans on and nothing else — no models, no migrations, no auth scaffolding. Schema and identity code (User, Role, Permission, migrations, factories) belong in the consuming application.

What this package provides
--------------------------

[](#what-this-package-provides)

NamespaceDescription`HiTaqnia\Haykal\Core\ResultPattern\Result`, `Error`Typed `Result` outcome and companion `Error` value object. Use in place of exceptions for expected, recoverable failures.`HiTaqnia\Haykal\Core\Tenancy\Tenancy`Process-local tenant context resolver. Exposes `setTenantId()`, `getTenantId()`, `clear()`.`HiTaqnia\Haykal\Core\Tenancy\TenantScope`Global Eloquent scope that constrains queries to the active tenant. Rows with a `NULL` tenant remain visible as shared records.`HiTaqnia\Haykal\Core\Tenancy\Concerns\HasTenant`Trait that marks an Eloquent model as tenant-owned. Applies `TenantScope`, auto-populates the tenant FK on `creating`, and declares the `tenant()` relation. Override `$tenantModel` / `$tenantForeignKey` per model.`HiTaqnia\Haykal\Core\Identity\ValueObjects\PhoneNumber`Iraqi phone number in E.164 canonical form with readable and compact formatters.`HiTaqnia\Haykal\Core\Identity\Casts\PhoneNumberCast`Eloquent cast between `PhoneNumber` and its E.164 string form.`HiTaqnia\Haykal\Core\Identity\Rules\PhoneNumberRule`Validation rule for the input shapes the value object accepts.`HiTaqnia\Haykal\Core\Http\Middlewares\PermissionsTeamMiddleware`Forwards the active tenant into Spatie's `setPermissionsTeamId()`. Registered under the alias `haykal.permissions.team`.What this package deliberately does **not** ship
------------------------------------------------

[](#what-this-package-deliberately-does-not-ship)

- **No User / Role / Permission models.** Each consuming app owns its auth model and its role/permission subclasses (typically extending Spatie's with `HasUlids`).
- **No migrations.** The `users`, Spatie permission tables, media, and notifications tables are owned by the application. See `hitaqnia/haykal-starter` for the canonical hitaqnia schema.
- **No factories, seeders, routes, or publishable config.** Pure library code.

Requirements
------------

[](#requirements)

- PHP 8.3 or later
- Laravel 13 or later
- `spatie/laravel-permission` ^6.21 (required — `PermissionsTeamMiddleware` calls `setPermissionsTeamId()`)

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

[](#installation)

```
composer require hitaqnia/haykal-core
```

Auto-discovered via `HaykalCoreServiceProvider`, which registers the middleware alias on boot. Nothing else is wired up — the package adds no migrations, no routes, no config files.

Usage
-----

[](#usage)

### Result pattern

[](#result-pattern)

```
use HiTaqnia\Haykal\Core\ResultPattern\Error;
use HiTaqnia\Haykal\Core\ResultPattern\Result;

$result = Result::success($order);
// or
$result = Result::failure(Error::make(code: 4001, message: 'Booking overlap.'));

if ($result->isSuccess()) {
    $order = $result->getData();
} else {
    $error = $result->getError();
}
```

### Tenancy

[](#tenancy)

```
use HiTaqnia\Haykal\Core\Tenancy\Concerns\HasTenant;
use HiTaqnia\Haykal\Core\Tenancy\Tenancy;

// Set the active tenant for the current request / process.
Tenancy::setTenantId($complex->id);

// Query scopes automatically filter to the active tenant.
Property::query()->get();

// Tenant-owned models declare their tenant relation + FK.
class Property extends Model
{
    use HasTenant;

    protected string $tenantModel = Complex::class;
    protected string $tenantForeignKey = 'complex_id';
}
```

`$tenantForeignKey` defaults to `tenant_id` — override per model when different models belong to different tenant types (`agency_id` on `properties`, `developer_id` on `projects`, …).

### Phone numbers

[](#phone-numbers)

```
use HiTaqnia\Haykal\Core\Identity\Casts\PhoneNumberCast;
use HiTaqnia\Haykal\Core\Identity\Rules\PhoneNumberRule;
use HiTaqnia\Haykal\Core\Identity\ValueObjects\PhoneNumber;

// In your User model (or any model with a phone column):
protected function casts(): array
{
    return ['phone' => PhoneNumberCast::class];
}

// In a Form Request:
'phone' => ['required', new PhoneNumberRule],

// Using the VO directly:
$phone = new PhoneNumber('07701234567');
$phone->getInternational();                // "+9647701234567"
$phone->getInternational(readable: true);  // "+964 770 123 4567"
$phone->getNational();                     // "07701234567"
```

Currently only Iraqi numbers (`+964`, mobile) are accepted.

### Middleware

[](#middleware)

Assign globally or per route group in `bootstrap/app.php`:

```
use HiTaqnia\Haykal\Core\Http\Middlewares\PermissionsTeamMiddleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withMiddleware(function (Middleware $middleware) {
        // Must run after the middleware that resolves the active tenant:
        $middleware->appendToGroup('web', [PermissionsTeamMiddleware::class]);
    })
    ->create();
```

Or via the alias: `haykal.permissions.team`.

Testing
-------

[](#testing)

The package has no runtime scaffolding to test in isolation. The monorepo's tests exercise these utilities in combination with test fixtures that mirror a real consuming application's shape — see `tests/Fixtures/` and `tests/Core/` in the monorepo repository.

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance92

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

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 ~0 days

Total

6

Last Release

45d ago

Major Versions

v1.0.0 → v2.0.02026-04-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/a71357d99589a129a83cc144fbde6250fce3f3d0fa3f442770ef79f47ed7d9b2?d=identicon)[mahdi-mk](/maintainers/mahdi-mk)

---

Top Contributors

[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")

### Embed Badge

![Health badge](/badges/hitaqnia-haykal-core/health.svg)

```
[![Health](https://phpackages.com/badges/hitaqnia-haykal-core/health.svg)](https://phpackages.com/packages/hitaqnia-haykal-core)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

9782.1M153](/packages/laravel-ai)[spatie/laravel-health

Monitor the health of a Laravel application

88011.3M149](/packages/spatie-laravel-health)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1232.2k16](/packages/fleetbase-core-api)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

59156.3k10](/packages/api-platform-laravel)

PHPackages © 2026

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