PHPackages                             natha-i96/property-tenant-auth - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. natha-i96/property-tenant-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

natha-i96/property-tenant-auth
==============================

Two-level Laravel Sanctum authentication for Property and Tenant tokens. Frankenphp-safe, no custom guard.

v0.1.0(yesterday)01↑2900%MITPHPPHP ^8.2

Since Jun 30Pushed yesterdayCompare

[ Source](https://github.com/natha-i96/property-tenant-auth)[ Packagist](https://packagist.org/packages/natha-i96/property-tenant-auth)[ RSS](/packages/natha-i96-property-tenant-auth/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

property-tenant-auth
====================

[](#property-tenant-auth)

[![Source](https://camo.githubusercontent.com/8c84cd7253e2d803879f4a0fb77eaa5563858f6508159e5d14bcce06e7a38b78/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6e617468612d2d69393625324670726f70657274792d2d74656e616e742d2d617574682d626c7565)](https://github.com/natha-i96/property-tenant-auth)[![Packagist](https://camo.githubusercontent.com/f1efcaba23b25174a3c9e96abae3e1f42b1d4f4a5a7af1134d7d89705be1163c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e617468612d6939362f70726f70657274792d74656e616e742d61757468)](https://packagist.org/packages/natha-i96/property-tenant-auth)

A reusable Laravel package that provides two-level Sanctum API authentication for **Property** and **Tenant** tokens. It is **Frankenphp-safe** because it uses Sanctum's default guard and standard `Authenticatable` models — no custom guard is required.

- **Property token**: long-lived token used by a property management system. Can issue scoped tenant tokens.
- **Tenant token**: short-lived token issued by a property token. Carries role and tenant scope.

---

Features
--------

[](#features)

- Two-level Sanctum token hierarchy (Property → Tenant).
- No custom Laravel guard; works with Frankenphp and Octane.
- Polymorphic `personal_access_tokens` via a merged morph map so host-extended models stay resolvable.
- Configurable model classes, route prefix, middleware, abilities, and throttle limits.
- Built-in artisan command to bootstrap properties and print their plain-text tokens.
- Property-scoped route binding for tenant resource actions.
- Independent test suite via Orchestra Testbench.

---

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

[](#installation)

### 1. Require the package

[](#1-require-the-package)

```
composer require natha-i96/property-tenant-auth
```

### 2. Publish the config

[](#2-publish-the-config)

```
php artisan vendor:publish --tag=property-tenant-auth-config
```

### 3. Publish and run migrations

[](#3-publish-and-run-migrations)

The package ships migrations for `properties`, `tenants`, and a polymorphic Sanctum `personal_access_tokens` table.

```
php artisan vendor:publish --tag=property-tenant-auth-migrations
php artisan migrate
```

### 4. Ensure Sanctum is configured

[](#4-ensure-sanctum-is-configured)

Make sure `config/sanctum.php` is API-only:

```
'guard' => [],
'stateful' => [],
```

and define an `api` rate limiter in `AppServiceProvider::boot()`:

```
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;

RateLimiter::for('api', function (Request $request): Limit {
    return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
```

### 5. Register the route middleware (optional)

[](#5-register-the-route-middleware-optional)

The package registers aliases automatically (`abilities`, `ability`, `tokenable.active`). Enable API throttling in `bootstrap/app.php` if you want per-route throttles to work:

```
$middleware->throttleApi();
```

---

Host model extension
--------------------

[](#host-model-extension)

The package provides base models under `NathaI96\PropertyTenantAuth\Models\Property` and `Tenant`. In your host application, extend them so factories and project-specific behavior remain local:

```
