Completed
Branch master (2f299a)
by Ron
09:20
created

AddPasswordChangeToUsers   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 8 1
A up() 0 18 1
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
use App\Settings;
7
use App\User;
8
9
class AddPasswordChangeToUsers extends Migration
10
{
11
    /**
12
     * Run the migrations.
13
     *
14
     * @return void
15
     */
16
    public function up()
17
    {
18
        Schema::table('users', function(Blueprint $table)
19
        {
20
            $table->timestamp('password_expires')
21
                ->nullable()
22
                ->after('active');
23
        });
24
        
25
        //  Add the epiration timer to the settings database table
26
        Settings::insert([
27
            'key'   => 'users.passExpires',
28
            'value' => '90'
29
        ]);
30
        
31
        //  Update all of the existing users to set the password expiration date
32
        User::where('password_expires', null)->update([
33
            'password_expires' => date('Y-m-d', strtotime('+30 days'))
34
        ]);
35
    }
36
37
    /**
38
     * Reverse the migrations.
39
     *
40
     * @return void
41
     */
42
    public function down()
43
    {
44
        Schema::table('users', function(Blueprint $table)
45
        {
46
            $table->dropColumn('password_expires');
47
        });
48
        
49
        Settings::where('key', 'users.passExpires')->delete();
50
    }
51
}
52