Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit cc46b11

Browse files
committed
Update README
1 parent 60e56bb commit cc46b11

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,65 @@ This is a two-factor authentication package for *Laravel*. It is heavily inspire
1313
- This package uses throttling to limit the number of unsuccessful authentication attempts in a certain amount of time.
1414
- The current version of this package is only guaranteed to work with Laravel >= 5.5. Version 1.* of this package works with Laravel 5.4. Versions of Laravel prior to 5.4 have not been tested.
1515

16+
## Important
17+
From _Laravel_ 5.8 and onwards, the default is to use `bigIncrements` instead of `increments` for the `id` column on the `users` table. As such, the default for this package is to use the same convention for the `user_id` column on the `two_factor_auths` table. If this is not what you want, you can change this in the published config file by setting the "big_int" option to `false`.
18+
19+
For users who have already installed this package and hence, already have ran the migrations for this package there are essentially two different scenarios:
20+
21+
1. You upgrade from _Laravel_ < 5.8 to 5.8 or later and have decided to keep using `increments` for the `id` column on the `users` table: You don't have to do anything. You might want to [change](#optional-correction) the signature of the `user_id` column on the `two_factor_auths` table from `increments` to `unsignedInteger` though.
22+
23+
2. You upgrade from _Laravel_ < 5.8 to 5.8 or later and have decided to make the switch to `bigIncrements` for the `id` column on the `users` table: You will have to make and run your own migration in order to update the `user_id` column on the `two_factor_auths` table appropriately.
24+
25+
### Optional correction
26+
Versions of this package prior to v2.3.0 incorrectly created the `user_id` column on the 'two_factor_auths' table using `increments` instead of `unsignedInteger`. Practically speaking, this error is of no concern. Although there is no need to have a _primary_ key for the `user_id` column, it doesn't hurt either. However, if for some reason you don't like this idea, it is safe to remove the _primary_ key using a migration of the form
27+
28+
```php
29+
<?php
30+
31+
use Illuminate\Support\Facades\Schema;
32+
use Illuminate\Database\Schema\Blueprint;
33+
use Illuminate\Database\Migrations\Migration;
34+
35+
class RemovePrimaryFromTwoFactorAuthsTable extends Migration
36+
{
37+
/**
38+
* Run the migrations.
39+
*
40+
* @return void
41+
*/
42+
public function up()
43+
{
44+
Schema::table('two_factor_auths', function (Blueprint $table) {
45+
$table->dropForeign(['user_id']);
46+
});
47+
48+
Schema::table('two_factor_auths', function (Blueprint $table) {
49+
$table->unsignedInteger('user_id')->change();
50+
$table->dropPrimary(['user_id']);
51+
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
52+
});
53+
}
54+
55+
/**
56+
* Reverse the migrations.
57+
*
58+
* @return void
59+
*/
60+
public function down()
61+
{
62+
Schema::table('two_factor_auths', function (Blueprint $table) {
63+
$table->dropForeign(['user_id']);
64+
});
65+
66+
Schema::table('two_factor_auths', function (Blueprint $table) {
67+
$table->increments('user_id')->change();
68+
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
69+
});
70+
}
71+
}
72+
```
73+
Note that you will need the [doctrine/dbal](https://packagist.org/packages/doctrine/dbal) package for this migration to work. Furthermore, if the `id` column on your `users` table is of type `bigIncrements` you will have to change the lines `$table->unsignedInteger('user_id')->change();` to `$table->unsignedBigInteger('user_id')->change();` and `$table->increments('user_id')->change();` to `$table->bigIncrements('user_id')->change();` respectively.
74+
1675
## Installation
1776
1. To install using *Composer* run:
1877
```
@@ -34,13 +93,17 @@ php artisan vendor:publish
3493
```
3594
If you want to publish only one of these file groups, for instance if you don't need the views or language files, you can append one of the following commands to the *artisan* command: `--tag=config`, `--tag=lang` or `--tag-views`.
3695

37-
4. Run the following *artisan* command to run the database migrations
96+
4. **Important**: Make sure you do this step _before_ you run any migrations for this package, as otherwise it might give you unexpected results.
97+
98+
From _Laravel_ 5.8 and on, the default is to use `bigIncrements` instead of `increments` for the `id` column on the `users` table. As such, the default for this package is to use the same convention for the `user_id` column on the `two_factor_auths` table. If this is not what you want, you can change this in the published config file by setting the "big_int" option to `false`.
99+
100+
5. Run the following *artisan* command to run the database migrations
38101
```
39102
php artisan migrate
40103
```
41104
This will add a `mobile` column to the `users` table and create a `two_factor_auths` table.
42105

43-
5. Add the following trait to your `User` model:
106+
6. Add the following trait to your `User` model:
44107
```php
45108
...
46109
use MichaelDzjap\TwoFactorAuth\TwoFactorAuthenticable;

0 commit comments

Comments
 (0)