1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Migrations\Migration; |
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
5
|
|
|
|
6
|
|
|
class CreateApiKeysTable extends Migration |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Run the migrations. |
10
|
|
|
* |
11
|
|
|
* @return void |
12
|
|
|
*/ |
13
|
|
|
public function up() |
14
|
|
|
{ |
15
|
|
|
Schema::create('api_keys', function (Blueprint $table) { |
16
|
|
|
$table->increments('id'); |
17
|
|
|
$table->integer('user_id', false, true)->nullable(); |
18
|
|
|
$table->string('key', 40); |
19
|
|
|
$table->smallInteger('level'); |
20
|
|
|
$table->boolean('ignore_limits'); |
21
|
|
|
$table->nullableTimestamps(); |
22
|
|
|
$table->softDeletes(); |
23
|
|
|
|
24
|
|
|
// unique key |
25
|
|
|
$table->unique('key'); |
26
|
|
|
|
27
|
|
|
// Let's index the user ID just in case you don't set it as a foreign key |
28
|
|
|
// $table->index('user_id'); |
29
|
|
|
|
30
|
|
|
// Uncomment the line below if you want to link user ids to your users table |
31
|
|
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('set null'); |
32
|
|
|
}); |
33
|
|
|
|
34
|
|
|
Schema::create('api_logs', function (Blueprint $table) { |
35
|
|
|
$table->increments('id'); |
36
|
|
|
$table->integer('api_key_id', false, true)->nullable(); |
37
|
|
|
$table->integer('user_id', false, true)->nullable(); |
38
|
|
|
$table->string('route', 255); |
39
|
|
|
$table->string('method', 6); |
40
|
|
|
$table->text('params'); |
41
|
|
|
$table->string('ip_address'); |
42
|
|
|
$table->nullableTimestamps(); |
43
|
|
|
|
44
|
|
|
$table->foreign('api_key_id')->references('id')->on('api_keys'); |
45
|
|
|
$table->index('route'); |
46
|
|
|
$table->index('method'); |
47
|
|
|
|
48
|
|
|
// Let's index the user ID just in case you don't set it as a foreign key |
49
|
|
|
$table->index('user_id'); |
50
|
|
|
|
51
|
|
|
// Uncomment the line below if you want to link user ids to your users table |
52
|
|
|
//$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');; |
53
|
|
|
}); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Reverse the migrations. |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
public function down() |
62
|
|
|
{ |
63
|
|
|
Schema::table('api_keys', function (Blueprint $table) { |
64
|
|
|
$table->dropForeign('api_keys_user_id_foreign'); |
65
|
|
|
}); |
66
|
|
|
|
67
|
|
|
Schema::table('api_logs', function (Blueprint $table) { |
68
|
|
|
$table->dropForeign('api_logs_api_key_id_foreign'); |
69
|
|
|
}); |
70
|
|
|
|
71
|
|
|
Schema::drop('api_keys'); |
72
|
|
|
Schema::drop('api_logs'); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.