Completed
Push — master ( 7ee247...f51536 )
by Zura
01:48
created

CreatePromocodesTable::up()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
6
class CreatePromocodesTable extends Migration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /**
9
     * Run the migrations.
10
     *
11
     * @return void
12
     */
13
    public function up()
14
    {
15
        Schema::create(config('promocodes.table', 'promocodes'), function (Blueprint $table) {
16
            $table->increments('id');
17
18
            $table->string('code', 32)->unique();
19
            $table->double('reward', 10, 2)->nullable();
20
21
            $table->text('data')->nullable();
22
23
            $table->boolean('is_disposable')->default(false);
24
            $table->timestamp('expires_at')->nullable();
25
        });
26
27
        Schema::create(config('promocodes.relation_table', 'promocode_user'), function (Blueprint $table) {
28
            $table->unsignedInteger('user_id');
29
            $table->unsignedInteger('promocode_id');
30
            
31
            $table->timestamp('used_at');
32
33
            $table->primary(['user_id', 'promocode_id']);
34
35
            $table->foreign('user_id')->references('id')->on('users');
36
            $table->foreign('promocode_id')->references('id')->on(config('promocodes.table', 'promocodes'));
37
        });
38
    }
39
40
    /**
41
     * Reverse the migrations.
42
     *
43
     * @return void
44
     */
45
    public function down()
46
    {
47
        Schema::drop(config('promocodes.table', 'promocodes'));
48
        Schema::drop(config('promocodes.relation_table', 'promocode_user'));
49
    }
50
}
51