PHPackages                             tyler36/confirmable-trait - 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. tyler36/confirmable-trait

AbandonedArchivedLibrary

tyler36/confirmable-trait
=========================

A simple trait to add the ability to confirm something

1.0.1(7y ago)018PHP

Since Jun 12Pushed 7y ago1 watchersCompare

[ Source](https://github.com/tyler36/confirmable-trait)[ Packagist](https://packagist.org/packages/tyler36/confirmable-trait)[ RSS](/packages/tyler36-confirmable-trait/feed)WikiDiscussions master Synced 1mo ago

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

Introduction
============

[](#introduction)

This package is designed to simplify confirming a model (eg. User).

- Users generate a confirmation model and are emailed the token.
- To confirm, a user must enter their email and the confirmation token sent with a set time limit
- Users can request a new confirmation token.

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

[](#installation)

- Install package

```
composer require tyler36/confirmable-trait

```

- Publish the assets via command line

```
php artisan vendor:publish --provider=Tyler36\ConfirmableTrait\ConfirmableServiceProvider

```

- Add trait to User model In your User model, add the following line

```
// App\User.php
use Tyler36\ConfirmableTrait\Confirmable;

Class User extends Model
...
    use Confirmable;

```

- Run the migrations Update the User table by running the published migrations

```
php artisan migrate

```

- Register the event

```
// App\Providers\EventServiceProvider.php
...
    protected $listen = [
        UserRequestedConfirmationEmail::class => [
            SendConfirmationEmail::class
        ]
    ];

```

- Update views Update the view in `ConfirmUserController.php` to point to the view page

```
// App\Http\Controllers\Auth\ConfirmUserController.php
...
    public function edit()
    {
        return view('auth.confirmation');
    }

```

You can either redirect all authenticated, unconfirmed users view applying the middleware or adding a simple link to the view. I like to add a notification to the profile page.

```
// view/user/show.blade.php
...
    @if($user->isNotConfirmed())
        @include('common.confirmation_required')
    @endif

```

```
// view/forms/confirmation.blade.php
...

    @csrf()

    {{-- FORM:      Email --}}

            @lang('user.email')

    {{-- FORM:      Token --}}

        @lang('confirmable::message.token')

    {{-- FORM:      Acceptance --}}

        @lang('confirmable::message.acceptance')

            I have read and agree to the terms and conditions and privacy policy of this site.

    {{-- FORM:      Submit --}}
    Submit

```

- Apply middleware This package comes with 2 middleware for protecting route.

### isConfirmed

[](#isconfirmed)

This middleware only allows confirmed members. IE. A member is currently logged in AND marked as confirmed. To register the middleware, update `App\Http\Kernel.php` as followed:

```
// App\Http\Kernel.php
...
protected $routeMiddleware = [
    ...
    'auth.confirmed'    => \Tyler36\ConfirmableTrait\Middleware\isConfirmed::class,
]

```

Of-course, you can change the middleware name ('auth.confirmed') to anything you.

### isNotConfirmed

[](#isnotconfirmed)

This middleware only allows unconfirmed members. IE. A member is currently logged in AND is NOT confirmed. To register the middleware, update `App\Http\Kernel.php` as followed:

```
// App\Http\Kernel.php
...
protected $routeMiddleware = [
    ...
    'auth.notconfirmed'    => \Tyler36\ConfirmableTrait\Middleware\isNotConfirmed::class,
]

```

Models
------

[](#models)

### User model

[](#user-model)

After adding this trait to the User model, several new functions are available:

- To check if the User has been confirmed (returns boolean).

```
$user->isConfirmed()

```

- To check if User is NOT confirmed (returns boolean).

```
$user->isNotConfirmed()

```

- To manual mark a user as confirmed

```
$user->markConfirmed()

```

- You can get the current confirmation model via a relationship

```
$user->confirmation

```

### Confirmation model

[](#confirmation-model)

This model holds a confirmation token and the email account associated with it.

- You can get the user via a relationship

```
$confirmation->user

```

#### Validating tokens

[](#validating-tokens)

This packaged is designed to confirm users by checking a record matching an email &amp; token exists. There are several layers to validation

- Check a confirmation token exists for the authenticated User

```
$confirmation = Confirmation::firstOrFail(['email' => auth()->user()->email]);

```

- Validate a user supplied $token within the time limit

```
$confirmation->validateToken($token)

```

You can override the default 24 hour time period by updating the confirmation model

```
// Confirmation.php
class Confirmation extends Model
{
    ...
    protected $validForHours = 24;

```

Factory Helpers
---------------

[](#factory-helpers)

2 additional factory state helpers are available for your User models

### 'isConfirmed' User state

[](#isconfirmed-user-state)

This will generate a user that has been confirmed. IE. 'confirmed' =&gt; true

```
factory(App\User::class)->states('isConfirmed')->create();

```

### 'isNotConfirmed' User state

[](#isnotconfirmed-user-state)

This will generate a user that is NOT confirmed. IE. 'confirmed' =&gt; false

```
factory(App\User::class)->states('isNotConfirmed')->create();

```

Translations
------------

[](#translations)

After publishing the assets, you can override package translations through the vendor translation files. Note the double colon after the package name.

```
// In PHP files
trans('confirmable::message.token.mismatch')

// In blade files
@lang('confirmable::message.token.mismatch')

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Total

2

Last Release

2881d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c68f48588d57835c170cde02444307a450b98cfab07c9674094b881545c13b76?d=identicon)[tyler36](/maintainers/tyler36)

---

Top Contributors

[![s-hendrix-iqnet](https://avatars.githubusercontent.com/u/180614482?v=4)](https://github.com/s-hendrix-iqnet "s-hendrix-iqnet (4 commits)")

---

Tags

laraveltrait

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/tyler36-confirmable-trait/health.svg)

```
[![Health](https://phpackages.com/badges/tyler36-confirmable-trait/health.svg)](https://phpackages.com/packages/tyler36-confirmable-trait)
```

###  Alternatives

[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[elgg/elgg

Elgg is an award-winning social networking engine, delivering the building blocks that enable businesses, schools, universities and associations to create their own fully-featured social networks and applications.

1.7k15.7k3](/packages/elgg-elgg)[neos/flow

Flow Application Framework

862.0M449](/packages/neos-flow)[neos/flow-development-collection

Flow packages in a joined repository for pull requests.

144179.3k3](/packages/neos-flow-development-collection)[rias/statamic-redirect

28298.4k](/packages/rias-statamic-redirect)

PHPackages © 2026

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