PHPackages                             rasulian/laravel-user-verification - 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. rasulian/laravel-user-verification

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

rasulian/laravel-user-verification
==================================

A package for user email and phone number verification with activation code

v1.0(8y ago)6391[1 issues](https://github.com/mehrancodes/laravel-user-verification/issues)MITPHP

Since Oct 14Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mehrancodes/laravel-user-verification)[ Packagist](https://packagist.org/packages/rasulian/laravel-user-verification)[ RSS](/packages/rasulian-laravel-user-verification/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

laravel-user-verification
=========================

[](#laravel-user-verification)

A simple package to activate the users by token and code number.

This package allows you to verify the users either by token to be sent by email and code number for SMS.

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

[](#installation)

This package can be used in Laravel 5.4 or higher.

You can install the package via composer:

```
composer require rasulian/laravel-user-verification
```

In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php file:

```
'providers' => [
    // ...
    Rasulian\Verification\VerificationServiceProvider::class,
];
```

You may add the following aliases to your config/app.php:

```
'aliases' => [
    // ...
    'Verification' => Rasulian\UserVerification\Facades\Verification::class,
```

Publish the package config and database migration file by running the following command:

```
php artisan vendor:publish --provider="Rasulian\Verification\VerificationServiceProvider::class"
```

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

[](#configuration)

### Migration

[](#migration)

The table representing the user model must be updated with the `verified` column. This update will be performed by the migration included with this package.

**Please make sure that you don't have the this column on your user table.**

If your user table name is not `users`, you may change that in the `config/verification.php`.

Now you can migrate the normal way you do:

```
php artisan migrate
```

### Middleware

[](#middleware)

This package provides an optional middleware throwing `UserVerifiedMiddleware`. Please refer to the [Laravel Documentation](https://laravel.com/docs/master/errors#the-exception-handler) to learn more about how to work with the exception handler.

To register the default middleware add the following lines to the `$routeMiddleware` array within the `app/Http/Kernel.php` file:

```
protected $routeMiddleware = [
    'user.verified' => \Rasulian\UserVerification\Middlewares\UserVerifiedMiddleware::class,
];
```

You may use this middleware for the routes that needs the user's email or phone number be verified:

```
Route::middleware('auth', 'user.verified')->group(function () {
    // Routes here
});
```

### Errors

[](#errors)

This package throws several exception. you may use `try\catch` statement or the Laravel exception handler.

- `UserIsVerifiedException` The given user is already verified
- `UserNotVerifiedException` The given user is not verified
- `VerifyTokenMismatchException` The given token is wrong or not available
- `VerifyCodeMismatchException` The given code is wrong or not available

Usage
-----

[](#usage)

### Route

[](#route)

By default this package provide one route to verify the user by token.

```
Route::get('user/verification/{token}', 'App\Http\Controllers\Auth\RegisterController@verifyUser')
    ->name('user.verify');
```

#### Overriding package route

[](#overriding-package-route)

To define your own custom routes, put the package service provider call before the `RouteServiceProvider` call in the `config/app.php` file.

```
/*
 * Package Service Providers...
 */
Rasulian\UserVerification\VerificationServiceProvider::class,

/*
 * Application Service Providers...
 */
App\Providers\RouteServiceProvider::class,
```

Then, add your custom route in your route file.

### Facade

[](#facade)

The package offers a facade Verification::.

### verification Config file

[](#verification-config-file)

After publishing the package config, it will be located at the `config` directory. You are free to change the table name for the `user` and the `user_verifications` which represents the fields for storing the token and code.

```
