Completed
Push — master ( eed8e4...38e21d )
by ARCANEDEV
9s
created

CreateAuthUsersTable::addCredentialsColumns()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
3
use Arcanedev\LaravelAuth\Bases\Migration;
4
use Arcanedev\LaravelAuth\Services\SocialAuthenticator;
5
use Arcanedev\LaravelAuth\Services\UserConfirmator;
6
use Illuminate\Database\Schema\Blueprint;
7
use Illuminate\Support\Facades\Schema;
8
9
/**
10
 * Class     CreateUsersTable
11
 *
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class CreateAuthUsersTable extends Migration
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Constructor
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    /**
21
     * Make a migration instance.
22
     */
23
    public function __construct()
24
    {
25
        parent::__construct();
26
27
        $this->setTable(config('laravel-auth.users.table', 'users'));
28
    }
29
30
    /* ------------------------------------------------------------------------------------------------
31
     |  Main Functions
32
     | ------------------------------------------------------------------------------------------------
33
     */
34
    /**
35
     * Run the migrations.
36
     */
37
    public function up()
38
    {
39
        Schema::connection($this->connection)->create($this->table, function (Blueprint $table) {
40
            $table->increments('id');
41
            $table->string('username');
42
            $table->string('first_name', 30)->nullable();
43
            $table->string('last_name', 30)->nullable();
44
            $this->addCredentialsColumns($table);
45
            $table->rememberToken();
46
            $table->boolean('is_admin')->default(0);
47
            $table->boolean('is_active')->default(0);
48
            $this->addConfirmationColumns($table);
49
            $table->timestamps();
50
            $table->softDeletes();
51
        });
52
    }
53
54
    /* ------------------------------------------------------------------------------------------------
55
     |  Other Functions
56
     | ------------------------------------------------------------------------------------------------
57
     */
58
    /**
59
     * Add credentials columns.
60
     *
61
     * @param  \Illuminate\Database\Schema\Blueprint  $table
62
     */
63
    private function addCredentialsColumns(Blueprint $table)
64
    {
65
        // Basic columns
66
        $table->string('email')->unique();
67
68
        if (SocialAuthenticator::isEnabled()) {
69
            $table->string('password')->nullable();
70
            // Social network columns
71
            $table->string('social_provider')->nullable();
72
            $table->string('social_provider_id')->unique()->nullable();
73
        }
74
        else {
75
            $table->string('password');
76
        }
77
    }
78
79
    /**
80
     * Add confirmation columns.
81
     *
82
     * @param  \Illuminate\Database\Schema\Blueprint  $table
83
     */
84
    private function addConfirmationColumns(Blueprint $table)
85
    {
86
        if (UserConfirmator::isEnabled()) {
87
            $table->boolean('is_confirmed')->default(0);
88
            $table->string('confirmation_code', UserConfirmator::getLength())->nullable();
89
            $table->timestamp('confirmed_at')->nullable();
90
        }
91
    }
92
}
93