|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Schema; |
|
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
5
|
|
|
use Illuminate\Database\Migrations\Migration; |
|
6
|
|
|
|
|
7
|
|
|
class CreateSubscriptionsTables extends Migration |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Run the migrations. |
|
11
|
|
|
* |
|
12
|
|
|
* @return void |
|
13
|
|
|
*/ |
|
14
|
|
|
public function up() |
|
15
|
|
|
{ |
|
16
|
|
|
Schema::create('plans', function(Blueprint $table) { |
|
17
|
|
|
$table->engine = 'InnoDB'; |
|
18
|
|
|
|
|
19
|
|
|
$table->increments('id'); |
|
20
|
|
|
$table->string('name'); |
|
21
|
|
|
$table->text('description')->nullable(); |
|
22
|
|
|
$table->string('group', 100)->nullable(); |
|
23
|
|
|
$table->integer('free_days')->default(0); |
|
24
|
|
|
$table->tinyInteger('sort_order'); |
|
25
|
|
|
$table->boolean('is_active')->default(0); |
|
26
|
|
|
$table->boolean('is_default')->default(0); |
|
27
|
|
|
|
|
28
|
|
|
$table->timestamps(); |
|
29
|
|
|
|
|
30
|
|
|
}); |
|
31
|
|
|
|
|
32
|
|
|
Schema::create('plan_prices', function(Blueprint $table) { |
|
33
|
|
|
$table->engine = 'InnoDB'; |
|
34
|
|
|
|
|
35
|
|
|
$table->increments('id'); |
|
36
|
|
|
$table->integer('plan_id')->unsigned(); |
|
37
|
|
|
$table->decimal('amount'); |
|
38
|
|
|
$table->enum('interval', ['day', 'month', 'year'])->nullable(); |
|
39
|
|
|
$table->integer('interval_unit'); |
|
40
|
|
|
|
|
41
|
|
|
$table->foreign('plan_id') |
|
|
|
|
|
|
42
|
|
|
->references('id')->on('plans'); |
|
43
|
|
|
|
|
44
|
|
|
$table->timestamps(); |
|
45
|
|
|
|
|
46
|
|
|
}); |
|
47
|
|
|
|
|
48
|
|
View Code Duplication |
Schema::create('plan_features', function(Blueprint $table) { |
|
|
|
|
|
|
49
|
|
|
$table->engine = 'InnoDB'; |
|
50
|
|
|
|
|
51
|
|
|
$table->increments('id'); |
|
52
|
|
|
$table->integer('plan_id')->unsigned(); |
|
53
|
|
|
$table->string('code', 100); |
|
54
|
|
|
$table->integer('value')->default(0); |
|
55
|
|
|
$table->integer('sort_order'); |
|
56
|
|
|
$table->boolean('is_consumable')->default(0); |
|
57
|
|
|
|
|
58
|
|
|
$table->foreign('plan_id') |
|
|
|
|
|
|
59
|
|
|
->references('id')->on('plans'); |
|
60
|
|
|
|
|
61
|
|
|
$table->timestamps(); |
|
62
|
|
|
|
|
63
|
|
|
}); |
|
64
|
|
|
|
|
65
|
|
|
Schema::create('subscriptions', function(Blueprint $table) { |
|
66
|
|
|
$table->engine = 'InnoDB'; |
|
67
|
|
|
|
|
68
|
|
|
$table->increments('id'); |
|
69
|
|
|
$table->integer('plan_id')->unsigned(); |
|
70
|
|
|
$table->string('subscriber_type')->nullable(); |
|
71
|
|
|
$table->timestamp('subscriber_id')->nullable(); |
|
72
|
|
|
$table->timestamp('start_at')->nullable(); |
|
73
|
|
|
$table->timestamp('end_at')->nullable(); |
|
74
|
|
|
$table->timestamp('cancelled_at')->nullable(); |
|
75
|
|
|
$table->timestamp('upgrade_at')->nullable(); |
|
76
|
|
|
$table->timestamp('downgrade_at')->nullable(); |
|
77
|
|
|
|
|
78
|
|
|
$table->foreign('plan_id') |
|
|
|
|
|
|
79
|
|
|
->references('id')->on('plans'); |
|
80
|
|
|
|
|
81
|
|
|
$table->timestamps(); |
|
82
|
|
|
|
|
83
|
|
|
}); |
|
84
|
|
|
|
|
85
|
|
View Code Duplication |
Schema::create('subscriber_consumables', function(Blueprint $table) { |
|
|
|
|
|
|
86
|
|
|
$table->engine = 'InnoDB'; |
|
87
|
|
|
|
|
88
|
|
|
$table->increments('id'); |
|
89
|
|
|
$table->integer('plan_feature_id')->unsigned(); |
|
90
|
|
|
$table->string('subscriber_type'); |
|
91
|
|
|
$table->integer('subscriber_id'); |
|
92
|
|
|
$table->integer('available')->nullable(); |
|
93
|
|
|
$table->integer('used')->nullable(); |
|
94
|
|
|
|
|
95
|
|
|
$table->foreign('plan_feature_id') |
|
|
|
|
|
|
96
|
|
|
->references('id')->on('plans_features'); |
|
97
|
|
|
|
|
98
|
|
|
$table->timestamps(); |
|
99
|
|
|
|
|
100
|
|
|
}); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Reverse the migrations. |
|
105
|
|
|
* |
|
106
|
|
|
* @return void |
|
107
|
|
|
*/ |
|
108
|
|
|
public function down() |
|
109
|
|
|
{ |
|
110
|
|
|
Schema::dropIfExists('subscriber_consumables'); |
|
111
|
|
|
Schema::dropIfExists('subscriptions'); |
|
112
|
|
|
Schema::dropIfExists('plan_features'); |
|
113
|
|
|
Schema::dropIfExists('plan_prices'); |
|
114
|
|
|
Schema::dropIfExists('plans'); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: