@@ -15,7 +15,7 @@ public function up()
1515 {
1616 Schema::create ('api_keys ' , function (Blueprint $ table ) {
1717 $ table ->increments ('id ' );
18- $ table ->integer ('user_id ' )->unsigned ();
18+ $ table ->integer ('user_id ' , false , true )->nullable ();
1919 $ table ->string ('key ' , 40 );
2020 $ table ->smallInteger ('level ' );
2121 $ table ->boolean ('ignore_limits ' );
@@ -25,22 +25,32 @@ public function up()
2525 // unique key
2626 $ table ->unique ('key ' );
2727
28- // Uncomment this if you want to link user ids to your users table
29- //$table->foreign('user_id')->references('id')->on('users');
28+ // Let's index the user ID just in case you don't set it as a foreign key
29+ $ table ->index ('user_id ' );
30+
31+ // Uncomment the line below if you want to link user ids to your users table
32+ //$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');;
3033 });
3134
3235 Schema::create ('api_logs ' , function (Blueprint $ table ) {
3336 $ table ->increments ('id ' );
3437 $ table ->integer ('api_key_id ' , false , true )->nullable ();
35- $ table ->string ('route ' , 150 );
38+ $ table ->integer ('user_id ' , false , true )->nullable ();
39+ $ table ->string ('route ' , 255 );
3640 $ table ->string ('method ' , 6 );
3741 $ table ->text ('params ' );
3842 $ table ->string ('ip_address ' );
3943 $ table ->nullableTimestamps ();
4044
45+ $ table ->foreign ('api_key_id ' )->references ('id ' )->on ('api_keys ' );
4146 $ table ->index ('route ' );
4247 $ table ->index ('method ' );
43- $ table ->foreign ('api_key_id ' )->references ('id ' )->on ('api_keys ' );
48+
49+ // Let's index the user ID just in case you don't set it as a foreign key
50+ $ table ->index ('user_id ' );
51+
52+ // Uncomment the line below if you want to link user ids to your users table
53+ //$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');;
4454 });
4555 }
4656
0 commit comments