PHPackages                             kylearch/ephemeral-users - 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. kylearch/ephemeral-users

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

kylearch/ephemeral-users
========================

Laravel package for ephemeral (non-persistent) user instances

v1.0.0(8mo ago)61.4kMITPHPPHP ^8.2

Since Oct 20Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/kylearch/ephemeral-users)[ Packagist](https://packagist.org/packages/kylearch/ephemeral-users)[ RSS](/packages/kylearch-ephemeral-users/feed)WikiDiscussions main Synced today

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

Ephemeral Users for Laravel
===========================

[](#ephemeral-users-for-laravel)

A Laravel package for creating ephemeral (non-persistent) user instances. Perfect for handling anonymous users, session-based users, or any scenario where you need a User object without database persistence.

Features
--------

[](#features)

- 🚫 **Prevent Accidental Persistence** - Ephemeral users throw exceptions when save attempts are made
- 📝 **Automatic Logging** - Track code paths that attempt to persist ephemeral users
- 🔧 **Configurable Behavior** - Choose between throwing exceptions or silently preventing saves
- 🎯 **Type Safe** - Full type hinting and interface support
- 📦 **Easy Integration** - Simple trait-based implementation

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

[](#installation)

Add the package to your Laravel application:

```
composer require kylearch/ephemeral-users
```

Publish the configuration file (optional):

```
php artisan vendor:publish --tag=ephemeral-users-config
```

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

Implement the interface and use the trait in your User model:

```
use KyleArch\EphemeralUsers\Contracts\EphemeralUser as EphemeralUserContract;
use KyleArch\EphemeralUsers\Concerns\HasEphemeralState;

class User extends Authenticatable implements EphemeralUserContract
{
    use HasEphemeralState;

    // Your existing User model code...
}
```

### Creating Ephemeral Users

[](#creating-ephemeral-users)

```
// Create an ephemeral user instance
$ephemeralUser = User::ephemeral([
    'id' => 'session-abc123',
    'email' => 'anonymous@example.com',
    'name' => 'Anonymous User',
]);

// Check if a user is ephemeral
if ($ephemeralUser->isEphemeral()) {
    // Handle ephemeral user logic
}

// Get the ephemeral identifier
$identifier = $ephemeralUser->getEphemeralIdentifier(); // 'session-abc123'
```

### Persistence Protection

[](#persistence-protection)

Attempting to save an ephemeral user will:

1. Log the attempt (if logging is enabled)
2. Throw an `EphemeralPersistenceException` (if configured)
3. Prevent the save operation

```
$ephemeralUser = User::ephemeral(['id' => 'test']);

try {
    $ephemeralUser->save(); // Throws EphemeralPersistenceException
} catch (EphemeralPersistenceException $e) {
    // Handle the exception
    $user = $e->getEphemeralUser();
}
```

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

[](#configuration)

The package supports the following configuration options:

```
return [
    // Throw exception on persist attempts (default: true)
    'throw_on_persist' => env('EPHEMERAL_THROW_ON_PERSIST', true),

    // Log persist attempts (default: true)
    'log_attempts' => env('EPHEMERAL_LOG_PERSIST', true),

    // Log channel to use
    'log_channel' => env('EPHEMERAL_LOG_CHANNEL', 'stack'),

    // Log level for persist attempts
    'log_level' => env('EPHEMERAL_LOG_LEVEL', 'warning'),
];
```

Use Cases
---------

[](#use-cases)

- **Anonymous Users**: Handle session-based users without database records
- **Testing**: Create test users without database persistence
- **API Integration**: Represent external users without local persistence
- **Guest Checkout**: Allow guest users with full User object interface
- **Sample/Demo Flows**: Enable trial experiences without account creation

License
-------

[](#license)

MIT

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance60

Regular maintenance activity

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

256d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1396751?v=4)[Kyle Arch](/maintainers/kylearch)[@kylearch](https://github.com/kylearch)

---

Top Contributors

[![kylearch](https://avatars.githubusercontent.com/u/1396751?v=4)](https://github.com/kylearch "kylearch (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kylearch-ephemeral-users/health.svg)

```
[![Health](https://phpackages.com/badges/kylearch-ephemeral-users/health.svg)](https://phpackages.com/packages/kylearch-ephemeral-users)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M193](/packages/laravel-ai)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k90.5k1](/packages/mike-bronner-laravel-model-caching)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M1](/packages/glushkovds-phpclickhouse-laravel)[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.

45444.2k1](/packages/pressbooks-pressbooks)

PHPackages © 2026

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